I've been using Vim for about 2 years now, mostly because I can't figure out how to exit it

Automated FTP Files Backup Using 7-zip Command Line - Windows Script

In my previous post I was talking about creating a Windows script to perform automated backup of your MySQL databases. We’ll do something similar today, except that we’ll use 7-zip command line version to perform automated FTP backups of files or folders in Windows.

I have tested this script on Windows XP, Server 2003, Vista and Windows 7 and it works fine. Again, there are some steps involved in getting this done:

  • Downloading the 7-zip Command Line version to your computer
  • Writing the script that will perform the backup
  • Creating a Windows Task that will automatically run the script
1. Downloading the 7-zip Command Line version to your computer

Get a copy of the 7-zip Command Line utility and save it on your computer (make sure you get the command line version).

In order to avoid adding the 7za.exe to my Windows path, I will save the file in my user's name folder on my Windows computer. So much with step 1.

2. Writing the script that will perform the backup

If you had a look at my previous post, you've probably seen the script I used to backup MySQL databases. Now, we'll take that script and we'll adjust it - so instead of creating a database dump, it will use the 7-zip utility to compress the given files or folders, and than upload them to your FTP server. So, here we go:

@echo off

SET today=%date:~-4,4%%date:~-7,2%%date:~-10,2%
SET SCRIPT_NAME=ftp_script.ftp

7za a -t7z "%today%_my_backup.7z" c:\path\to\my\folder\to\backup

echo open>> %SCRIPT_NAME%
echo ftp_username>> %SCRIPT_NAME%
echo ftp_password>> %SCRIPT_NAME%
echo cd path/storage/folder>> %SCRIPT_NAME%
echo binary>> %SCRIPT_NAME%
echo put %today%_my_backup.7z>> %SCRIPT_NAME%
echo disconnect>> %SCRIPT_NAME%
echo bye>> %SCRIPT_NAME%
ftp -s:%SCRIPT_NAME%

@del %SCRIPT_NAME% /q
@del %today%_my_backup.7z

Save this also inside your user's name folder. As you can see in the above screenshot, I've named mine "run_backup.bat" - but you can choose a more descriptive name.

3.Creating a Windows Task that will automatically run the script

For this you'll need to create a Windows Task, assign a backup time and date for it, and point it to run the script you've just create. Follow the steps I've described in my previous post, at Step 2 - the procedure is identical.

As usual, before trusting the script, just run it first and make sure that all is fine and your backup gets actually created. Right click onto the newly created task and choose "Run" to test it out.

I know that there's a bit of confusion about getting your backups done and lots of people think that for this kind of job (automated FTP backups) - an FTP client is required.

However, there are utilities out there doing FTP automated backups – some very good, some not so good, some free and some that require payment. If you are going to use one of them, I would recommend Cobian Backup 8, which is Open Source. I've used it and it's pretty decent (I like the email backup notifications).

Right on, that would be all for now. Please share with us in comments about what other apps/scripts are you using to perform automated backups (FTP or not).

Till next time - keep good.