{"id":427,"date":"2007-05-09T07:54:24","date_gmt":"2007-05-09T12:54:24","guid":{"rendered":"http:\/\/teamtutorials.com\/windows-tutorials\/create-a-windows-daily-backup-script"},"modified":"2007-05-17T09:33:38","modified_gmt":"2007-05-17T14:33:38","slug":"create-a-windows-daily-backup-script","status":"publish","type":"post","link":"https:\/\/teamtutorials.com\/windows-tutorials\/create-a-windows-daily-backup-script","title":{"rendered":"Create a Windows Daily Backup Script"},"content":{"rendered":"
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.<\/p>\n
First you will need to open notepad. The easiest way is going to start > run and typing notepad.
\n<\/p>\n
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 \u2018test\u2019 that I want to backup to a folder called \u2018backup 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)
\n<\/p>\n
Now I will explain the command \u201cxcopy c:\\test\\* x:\\backup\\%date:~0,3%\\* \/Y \/Q \/S\u201d<\/p>\n
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\u2019t be automated. \/Q doesn\u2019t 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 \/?.<\/p>\n
Where you see \\%date:~0,3%\\ is the name of the destination folder. If you didn\u2019t 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. <\/p>\n
Once you have made the changes that you nee, save the file as backup.bat
\n<\/p>\n
Now Open the Control Panel and select Scheduled Tasks
\n<\/p>\n
Now we want to add a new task so click the \u201cAdd Scheduled Task\u201d button.
\n<\/p>\n
Click next and then browse. Locate the backup script you just saved and click open.
\n<\/p>\n
Select perform this action daily and then click the next button.
\n<\/p>\n
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.
\n<\/p>\n
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.)
\n<\/p>\n
Click finish. Now we can test the backup script. Located the script in the scheduled tasks folder, Right click it and select run.
\n<\/p>\n
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.
\n<\/p>\n
This is a very basic idea of how to use the task scheduler and batch files to make backups.<\/p>\n","protected":false},"excerpt":{"rendered":"
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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,12],"tags":[],"yoast_head":"\n