Create a Windows Daily Backup Script

This tutorial will show you how to use a simple Windows Batch file and the task scheduler to create an automated daily backup. We will use the date variable to backup the files into folders with the first three letters of the day as the folder name.

First you will need to open notepad. The easiest way is going to start > run and typing notepad.
Create a Windows Daily Backup Script

We will use notepad to create are batch file. A windows batch file is a set of instructions that tells the computer what to do. All we really need to do is add the command to copy the folder that we want to backup. I have a folder called ‘test’ that I want to backup to a folder called ‘backup on a network drive which I have mapped as the x drive. It only takes one simple command to do that actual backup. (note: there is no | in the command next the the word date, that is just the cursors)
Create a Windows Daily Backup Script

Now I will explain the command “xcopy c:\test\* x:\backup\%date:~0,3%\* /Y /Q /S”

The xcopy commands will copy files and folders. The syntax for the command is xcopy [destination] [arguments]. Where source is the folder that you want to backup and destination is the backup on the network drive. The arguments tell xcopy how to handle certain situations. For my script I used /Y to suppress prompting when overwriting files. If you do not include this the script will ask you before copying each file, that wouldn’t be automated. /Q doesn’t display the file names while copying. /S copies directories and sub directories. You can find more arguments by opening the command windows and typing xcopy /?.

Where you see \%date:~0,3%\ is the name of the destination folder. If you didn’t want to change the name daily you could simple call it \backup\ or something like that. The %date% is a variable. If you type %date at the command line, you will get the current date and time output. The :~0,3 tells the command line to return the first three letters of that date (0-3) and trim off the rest.

Once you have made the changes that you nee, save the file as backup.bat
Create a Windows Daily Backup Script

Now Open the Control Panel and select Scheduled Tasks
Create a Windows Daily Backup Script

Now we want to add a new task so click the “Add Scheduled Task” button.
Create a Windows Daily Backup Script

Click next and then browse. Locate the backup script you just saved and click open.
Create a Windows Daily Backup Script

Select perform this action daily and then click the next button.
Create a Windows Daily Backup Script

Select enter the time you want the task to run at in the start time box. Then make sure daily is selected and change the date to the day you would like this task to start running on.
Create a Windows Daily Backup Script

Enter your password and click next. (note: if you do not have a password, you may have problems with the scheduled tasks running correctly. I recommend adding a password to your account, or setting up a separate account to run scripts.)
Create a Windows Daily Backup Script

Click finish. Now we can test the backup script. Located the script in the scheduled tasks folder, Right click it and select run.
Create a Windows Daily Backup Script

You should see the command window open. When the task is finished, browse to your backup folder and verify that the files have been copied.
Create a Windows Daily Backup Script

This is a very basic idea of how to use the task scheduler and batch files to make backups.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join the TeamTutorials mailing list and get the latest tips, tricks, and special discounts for members only.

Thanks! Please click the link in the email we just sent you to confirm.