Backup Script for Windows

If you are running a web server under Windows, chances are that you need to backup your website regularly. So instead of doing the copy process manually, some server Administrators prefer to write a script that automates the backup operation.

A friend has recently asked me to make a backup script for his server and I though of sharing it here.

The backup script does two things:

  1. Backup all the files in the specified folder and append a date to its name
  2. Creates a log file on each backup instance so that the Admin knows what has been copied or what hasn’t.

Download Link: http://download.jcplaboratory.org/MISC/winsrv_backup_script/srv_backup_script.zip

Setting-up the script

I have used different variables to define the different locations; the path of the folder to backup, the destination folder and logs directory.

So here are the variables you need to change (See picture above):

  1. Path = Backup destination directory
  2. locationThe folder you want to backup on your server
  3. loglocLog files location (Where you want the log files to be kept)

Configuring new Task Scheduler job

Now that you have your backup script ready we’ll need to set up new Task Scheduler job to make it run automatically at the date and time we desire.

  1. Go to Start, Type Task Scheduler and open it
  2. From the Menu Bar, click Action>Create Task

Now, give your job a name and change the user with which you want the job to be executed. Preferably, select a user with Administrative rights and select the “Run with highest privileges” check box.

3. Navigate to the “Trigger” tab and create a new trigger.

A trigger allows you to specify when the task should start. Adjust it according to your needs. For instance, in the picture below, I’ve scheduled the task to run on every 30th of each month.

4. Press OK and navigate to the action tab.

We have now to specify what should to task do when it runs. In our case, we want it to execute our backup script.

5. Press OK and save the task.

You are all set, the script should now be executed on the date and conditions you specified.