UPDATE:After further testing I have determined that THE BACKUPS ARE BROKEN. Two things break them. One, when the command prompt saves the snapshot to notepad, it adds an [enter] to each line, causing serverquery to read each line as a command. In addition, the command prompt saves the snapshot using ASCII encoding instead of UTF-8, causing the snapshot to lose characters and corrupting the checksum, causing serverquery to deny it as a snapshot, rendering it useless, even if one takes the time to remove all the extra [enter]s placed into the snapshot. I will will leave this article here in the hopes that someone can find it useful and fix the problems caused when command prompt records the snapshot.
I recently found a way to automate server backup of windows, and decided to share this information since I could not find it elsewhere. This is a method for backing up a locally hosted windows teamspeak server.
This makes use of serverquery and the serversnapshotcreate command. What this method does, is it uses a batch file to telnet into the teamspeak server serverquery. Then an autohotkey script inputs credentials and the necessary commands to create a serversnapshot and save it to a text file. Windows Task Scheduler is used run the script daily.
Note: I have attempted to Bold and Italicize the parts of code that need to be configured with your specific values
Important: Only one backup will be kept per day. Re-running this script will overwrite the textfile where the backup is saved with the newest settings.
The Process:
Enabling Telnet:
- First enable Telnet in the command prompt by going to Control Panel, Programs and Features, and click "Turn Windows Features On or Off"
- Check "Telnet Client" and let it install
Creating the Batch File
- Create a directory for your backups I.E "C:\Users\Josh Calvin\Google Drive\TeamSpeak 3 Server\Backups"
- Create a text file and input
Code:telnet 127.0.0.1 10011 -f "Backup Directory Path\Backup %DATE:/=-%.txt"- Example:
Code:telnet 127.0.0.1 10011 -f "C:\Users\Josh Calvin\Google Drive\TeamSpeak 3 Server\Backups\Backup %DATE:/=-%.txt"- Save it as BatchBackup.bat in your backup directory
Installing Autohotkey
- Download and install Autohotkey from https://autohotkey.com/
Creating the Script
- Navigate to your backup directory
- Rightclick and choose New>Autohotkey Script
- Name it what you like. I named mine "Auto Backup"
- Rightclick and click edit
- Input
Code:#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. #SingleInstance Force Run, BatchBackup.bat, Backup Path Directory, Min Sleep, 1000 SetTitleMatchMode, 2 ControlSend, , login Username Password{enter}, Telnet 127.0.0.1 Sleep, 200 ControlSend, , use sid=1{enter}, Telnet 127.0.0.1 Sleep, 200 ControlSend, , serversnapshotcreate{enter}, Telnet 127.0.0.1 Sleep, 20000 ControlSend, , quit{enter}, Telnet 127.0.0.1 Return- Example:
Code:#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. #SingleInstance Force Run, BatchBackup.bat, C:\Users\Josh Calvin\Google Drive\TeamSpeak 3 Server\Backups, Min Sleep, 1000 SetTitleMatchMode, 2 ControlSend, , login serveradmin P4$$w0rd{enter}, Telnet 127.0.0.1 Sleep, 200 ControlSend, , use sid=1{enter}, Telnet 127.0.0.1 Sleep, 200 ControlSend, , serversnapshotcreate{enter}, Telnet 127.0.0.1 Sleep, 20000 ControlSend, , quit{enter}, Telnet 127.0.0.1 Return- Notes: This assumes that your telnet port is 10011 (default) and your server id is 1 (default)
Converting the AHK to an EXE
- In order to run the script daily it needs to be converted to an executable
- In AutoHotKey's installation directory is a file called "Ahk2Exe.exe"
- Run it and name the exe what you like. I named mine "Auto Backup"
Configuring Autobackup
- Open start and type "Task Scheduler"
- Create a basic task, name it, choose daily (or the preferred setting), start a program, and select the executable you made. I.E "Auto Backup.exe"
--------------------------------------------------------------------------------
Restoring a Backup
- Open command prompt and type
Code:telnet 127.0.0.1 10011 login Username Password use sid=1 serversnapshotdeploy Serversnapshot text- Example:
Code:telnet 127.0.0.1 10011 login serveradmin P4$$w0rd use sid=1 serversnapshotdeploy hash=6cpOXuNrdb04J+AQwZcsiUe21r0=|virtualserver_unique_identifier=Fv1HJXuhFh03uE 8QgXRb1OcIbdY= virtualserver_name=...permnegated=0|end_flat|channel_client_flat end_flat|end_permissio ns- Note: The serversnapshot is a large amount of text that gets larger the more confifurations your channel has. I left out most of it to conserve space.
Good luck!