Jump to content

Automatic Backup Script


Recommended Posts

I wanted to make a simple tutorial for those that don't know how to make an automated backup for their server. Backups are very important, but I find myself forgetting to do them frequently, so here is the solution!

First off is the batch file, I will post mine and explain a little about it.

xcopy /i /e /f C:\Users\*\*\Server \\*\*\Backup\"%date%"

The *'s are put in place of my directory, you should replace "C:\Users\*\*\Server" with the directory to your server files, and "\\*\*\Backup\" with where you want the backups to be saved.


The reason my second file path doesn't have a drive letter and only two slashes is because it is a network drive, which is ideal for backups. It would work if you saved your backups to the same machine that the server is running on. but it wouldn't be much help if that computer broke somehow, external backups are always better.


Now, there isn't much else to explain because its very simple. Xcopy is a windows command, more info about it can be found here. The %date% section grabs the current date from the computer and makes it the files name, in conjunction with the /i parameter It will create a new folder named the current time whenever the script is run.


Once you have a text file with the script typed it, and the correct file paths, save it with the extension .bat instead of .txt, then run it and see if there are any errors. One common one may be the file name. Another common issue is the fact that the xcopy command doesn't like when there are spaces in filenames, if you have any files in your path that include spaces, replace them with something else like an underscore.


By default (for North America at least) the date format contains a slash. You cannot have a slash in a file name, so to change this navigate to the date and time settings on your computer, the easiest way to do this is to click the time in the lower right corner, and click date and time settings. On windows 10 you should see related settings on the right side, click the one called "Date, time & regional formatting". Click change data formats on the bottom, and change the short date to the one that has hyphens instead of slashes.


After you verified that the script works as intended, you can set up the task scheduler to actually make it run automatically.


To do this open task scheduler by pressing the windows key and typing in "task scheduler".

Once open, on the right side of the window you will see the "Actions" tab, in there select the option to create a basic task.

Give the task a name, select how often you want the back up to occur, select the time and day you want it to happen, and finally choose the "start a program" option. After clicking next, select browse to find your batch file and select it.


After that It is complete and should run the script at your selected date and time! I have mine backing up every week, It is fine to run a backup while the server is running so no need to shut it off first.


If you have any problems post a comment and I'll try to help, but google knows all, and this is a relatively simple script, it shouldn't be hard to fix any errors after a couple minutes of searching. :grog:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...