Perform Automatic Backups using Hstart, 7-Zip and WinSCP
Most people think about backups only after losing their data due to a hard drive failure or a foolish mistake. I use 7-Zip for my backup scenarios as it is very flexible and all of its features can be accessed from the command line. 7-Zip is best used for backing up documents or projects with tons of text files.
This tutorial describes how to write a simple backup scenario into a batch file. The backup must have a proper name, be password protected and automatically uploaded to a web host.
A simple call of the command line version of 7-Zip looks like the following:
You may have a bunch of directories to backup. To simplify this process, you can create inclusion and exclusion lists of files and directories that you want to backup. The password is required if you want to store your personal data in a file server afterwards.
After some tests, you may have something like the following:
Open WinSCP and create a new session to your web host with your user name and password. You can use FTP or SFTP/SCP if your server supports them.
Now you can use WinSCP scripting/console interface to connect to your server and upload backup files in an unattended mode.
Below is a complete batch file that performs backups using 7-Zip and WinSCP:
set BackupFile=E:\Backup\backup_%FileDate%.7z
del %BackupFile%
"C:\Program Files\7-Zip\7z.exe" a -t7z -mhe=on -mx=1 -pYourSuperPassword %BackupFile% -i@backup_include.txt -xr@backup_exclude.txt
rem Generate temporary script to upload %BackupFile%
echo option batch on > script.tmp
echo option confirm off >> script.tmp
echo open account@domain.com >> script.tmp
echo put %BackupFile% >> script.tmp
echo exit >> script.tmp
rem Execute script
"C:\Program Files\WinSCP\winscp.com" /script=script.tmp
rem Delete temporary script
del script.tmp
Use Hstart to run the backup script in the background and display a simple message:
/TITLE="7-Zip Backup" /MSG="Backup is completed successfully!"
/ERRMSG="An error occurred while backing up data." daily-backup.bat
Once you setup a repeatable backup process in Task Scheduler, you are done with it.
The sample files are included in the Hstart package (see Examples\Backup).
Quick Links
Home • Tutorials • Perform Automatic Backups using Hstart, 7-Zip and WinSCP