We all need to backup our data from time to time, be it project, personal or even miscellaneous. And, I’m no exception either! So here I was routinely taking backups using the customary Ctrl+C, Ctrl+V (Copy, Paste) in Windows, and then from nowhere an idea of an automatic script popped up, but it wasn’t long, before my indolent-self gave up seeing the amount of googling I would have to do in order to come up with something-even-remotely-working, as my scripting skills are no better than a 4 year old’s! But, somehow I stood up against all odds (Lol) and the rest was history!
The things which you’ll need:-
- Windows Vista or above (it means Windows 7 ;))
The following is the script which not only takes the backup but also compresses it. That’s what I call efficient programming!
And if you thought, it was only enough, you also get a log file containing all the details of the copy operation, absolutely free!
@ECHO OFF REM Script to backup the data. REM Author - Ankeet Maini REM Last Updated - 23rd April, 2012 REM Minimum requirements: Windows Vista and above, 7-Zip ECHO Starting back-up process. ECHO Copying files... REM robocopy is the Windows Robust File Copy Command REM robocopy[Syntax] <source> <destination> [options] REM Source folder = "D:\Project\Dummy" REM Destination folder = "D:\Backups\Project-Backup-%date%" robocopy "D:\Project\Dummy" "D:\Backups\Project-Backup-%date%" /e /v /np /log+:"D:\BackupLogs.txt" ECHO Files copied. ECHO Compressing the backup data using 7-Zip... START "Compressing the backup..." /wait "C:\Program Files\7-Zip\7z.exe" a -tzip -r -mx5 "D:\Backups\Project-Backup-%date%" "D:\Backups\Project-Backup-%date%" ECHO Data is compressed. ECHO Cleaning up... RMDIR /S /Q "D:\Backups\Project-Backup-%date%" ECHO Finished cleaning, and backing up.
All you need to do is to change the SOURCE, DESTINATION, Log file and 7-Zip folders’ paths and you’re good to go. The above script copies the data and puts it to the destination path while appending the current system date to the folder name for easy restoration later!
To actually execute the script, copy paste the above code in a notepad, and change the extension to .bat, run the batch file after altering the source folder(of which you want to take the backup), destination folder(the place where you want to save the backup) and you’re done!
You can check the log file in case something went awry. You can even go a step further and schedule it in Windows scheduler to make it run automatically on a specified date and time.
So try it out, and if you stumble across something even better, do let me know!