Search The Site

How To Create Batch Files For Data Backup

How to backup your data using batch files. Today I will teach you an advanced method that allows for a lot of control when backing up important data files. You can open up your favorite text editor such as Notepad and then save the file as a .bat file to make it an executable. In the batch file, you can use the XCopy command to copy specified directories to another location. For example you can automatically backup files to an external drive or flash drive. After you have completed the batch file, you can add it to your scheduled task list and have the batch file run automatically at specified times. To add your batch commands to the task scheduler open up Control Panel and then click Performance and Maintenance, next, click Scheduled Tasks. Follow the wizard to schedule your batch file to run daily or weekly.

Let’s make our first batch file and test it out.

  • Open up Notepad or your favorite text editor and paste the following information into it.
  • xcopy /e /v /y c:\Music e:\Backup\Music
  • Save the file as backup.bat as seen in the illustration below.

create batch  files for backup

Notice when we save the file we have to choose All Files in order to give the file the .bat extension.

The above batch file will copy c:\music to the new backup location which is e:\backup\music. E Drive is my external hard drive. The /e makes sure XCopy copies subdirectories. The /y makes it so your are not prompted to verify an overwrite. The /v just makes it so the computer verifies the copy.

In the above example I used drive E:\ as the external drive letter. If your flash drive or external drive is labelled different you will have to change the E:\ to the letter of your drive. Your drive could be labelled F:\ or G:\ or X:\.

Go ahead and double click the new batch file to test it out. It is a lot easier than finding the files by hand and then copy and pasting them. Add the batch file command to your scheduled tasks list and you are done.

Congratulations you have just created your first batch file for data backup purposes.