Automate a backup (Windows) with 7z and a batch file

This is something which I found worked on Server 2003, and, I presume that it would work on Server 2008. I had a Windows server on one side of town and a Linux server on the other side of town. I wanted to grab a copy, nightly, of a particular mysql database (by just archiving a directory and downloading it, via a Linux cron job at my house). Anyway, this is how you can do something like that – or simply automate any sort of archiving – using 7zip on a Windows box.
Just install 7zip and, if I recall correctly, copy the file “7z.exe” to the system32 folder (it will be in the 7zip program directory). Sufficing a clumsy explanation, I’ll just show you the batch file that I used to archive the folder and move it a web accessible spot on IIS – and then delete the rascal. I just ran the 7zip procedure as a scheduled task

@ECHO OFF

cd "C:\Documents and Settings\All Users\Application Data\MYSQL\MySQL Server 5.5\data"
7z a my_database.zip my_database
move my_database.zip "C:\Inetpub\wwwroot\downloads\my_database.zip"
cd "C:\Inetpub\wwwroot\downloads"
ping 1.1.1.1 -n 1 -w 600000>NUL
del my_database.zip

exit

Leave a Reply