Automatic Backup help

I went through the great tutorial for the automatic backups ( and got the domain and database backups working great.

But once I get to Automatic FTP downloading of archive, I’m stuck…
I’m on a Mac (OS 10.4.7), and need to know how I should script the auto downloads.
I’m setup with ssh for passwordless login, so I’d like to use sftp or rsync, but have no ideal how I need to write the script. I’d searched the net, tried different things, but have given up at this point.
I was able to get rsync to download the files from dreamhost, but couldn’t figure out how to get it to delete the files off the dreamhost server after they were downloaded.

A shell script that I could then call from a local cron job would be fine for me.


I have no clue how closely Mac and linux correlate, but I was working on getting a script set up to download via SFTP my backups, since my windows install crashed and I’m now running Ubuntu. I think this script was working for me, but no promises… heavn’t had time to work with it recently.

Here’s the basics for my system. I had to set up a passwordless login for SSH, which carried over for SFTP as well. With that working I could now use the command line “sftp” program with a batch file.

This is my shell script that cron would run:
cd /home/matttail/backups/
sftp -bftp

and this is the batch file for sftp (that’s called “ftp” above):
#sftp batchfile
cd backups/
get archives/*
rm archives/*

I’m thinking that ‘progress’ visually shows how the downloads are going, and since a window doesn’t pop up with cron as it does in Windows you probably want to ditch that line. Hope this is of some help to you. If you get it working, this information should be added to the wiki article.

–Matttail - personal website

The rsync command should look something like this:

rsync -avz -e ssh USER@DOMAIN.COM:/home/USER/DIRECTORY ~LOCALUSER/backupdirectory

do -avzn if you want a dry run to see what will really happen.

With a carefully crafted shell script, you can then delete the DreamHost files you’ve downloaded with a for/each loop, or you can just blindly delete that directory and its contents and then re-create the directory (this is safer than using a wildcard to delete):

ssh USER@DOMAIN.COM /bin/rm -rf /home/USER/DIRECTORY


I was able to use Scott’s suggestion and get it to work.

I wasn’t able to use what Matttail provided, as I got some errors, and didn’t really have time to try and figure it out. :frowning:

But, success with Scott’s suggestion, and it’s working great. I just had it delete the directory and re-create.