Almost all my files are kept on Google Drive. I worry however that I’ll accidentally delete or modify a file that I need. I therefore created the batch file to copy all files and folders within my Google Drive account, to a local folder. There are numerous services that’ll backup your Google Drive content to cloud storage (e.g. Amazon Web Services S3). but these typically involve some cost and I have so much available local hard disk space I may as well use it for backups.
The simplest way to create a batch backup script
Here is the objective of this tutorial; backup defined folders and files in Windows 8, zip the backup, add a timestamp to the backup filename and add the compressed backup file to a specific local folder.
Here is what we’ll be doing:
- Installing the command line version of 7-zip software.
- Creating a batch file.
- Scheduling the batch file.
How to install 7-Zip to use in a batch file
There are two versions of the very awesome 7-Zip software; a GUI version and a command line version. For this tutorial we’ll use the command line version but I fully recommend using 7-ZIP for your primary compression software.
- Go to the 7-Zip download Page and download the 7-Zip Command Line Version.
- Extract the contents of the downloaded zip file to your PC (for this example I’ll use the path “C:usersmmouseprogram files7-zip”).
- In Windows go to System Properties then the Advanced tab and click Environment Variables.
- Under System Variables, click Path then Edit…
- Add the following to the end of any content in the Variable value: field C:Program Files7-Zip;
- Click OK until you’re out of the System Properties
Well done. You’ve now installed 7-Zip and enabled it to be used in a batch file.
How to create the backup batch file
Now for the fun bit. We’ll do the following:
- Create a batch file
- Enter script that will; copy and compress the contents of your chosen files and folders to a location of your choice. We’ll also add the date and time to the filename.
For this we’ll assume that we want to create a backup of all files and folders in “C:usersmmousegoogle drive” and place the backup in “C:usersmmousebackups”.
Let’s get started.
- In a text editor such as the awesome and free Notepad++, create a file called backup.bat (you may save the file anywhere on your computer but rememebr where you’ve saved it).
- In the file place the following:
@ECHO OFF SET hr=%time:~0,2% IF %hr% lss 10 SET hr=0%hr:~1,1% Set TODAY=%date:~4,2%-%date:~7,2%-%date:~10,4%-%hr%%time:~3,2%%time:~6,2%%time:~9,2% ECHO. ECHO Compressing files and folders in C:usersmmousegoogle drive and moving to C:usersmmousebackups ECHO. 7za a -tzip "C:usersmmousebackupsgoogle-drive-%TODAY%.zip" "C:usersmmousegoogle drive*" -mx5 ECHO. PAUSE
- Save the file.
Double click the file you’ve created called backup.bat. If working correctly you should see the command / CMD screen appear and you’ll be prompted if you want to continue. When continuing a backup will be performed (depending on the amount of data this could take quite awhile) and you’ll get a message saying Everything is complete… when the backup is done.
Scheduling the backups
Scheduling the backup script to run is really simple. All you need do is create a Windows scheduled task and use the backup batch file we created above.
Wow, that’s it. You’ve now created a regular backup of your chosen files and folders.