Rsync Backup

Remote backups with rsync (MacOS => Ubuntu)


Test you can log in without password prompt.

sudo ssh -i /backup/ssh_key

If you don't look the appendix

#Notice we are using --dry-run :)
sudo rsync -avz --dry-run -e "ssh -i /Users/emilianoburgos/.ssh/" ./lib root@

-avs - All objects, verbose output, do not allow remote shell to interpret characters; in other words, file names with spaces and special characters will not be translated, which is what you want most likely, especially if you have Windows files, too.

--delete will delete files at the target (destination), if they do not exist in the source. This means you will always keep an up to date list of files and the source and destination will match, plus the destination will not slowly grow in size with older, perhaps irrelevant content.

Advanced options

There are a million, literally. So here's a sampling of good things:

Likewise, the option --files-from=FILE allows you to specify a detailed list of directories you wish to include in your backup. Please note that if you write down directory paths without trailing slash, they will be recreated blank, and if you do add the trailing slash, their content will also be copied.

Cron job

Read about pipes

We are appending both standard output and standard error to a log file sync.log. If you only want to output standard error, use 2>> sync.log If you use > instead of >> you will be overriding instead of appending- so that your file does not grow to big.


echo "Start rsync job"
sudo rsync -avz --dry-run -e "ssh -i /Users/emilianoburgos/.ssh/" ./lib root@ &>> sync.log

exit 0


* */1 * * * /home/roger/


Create keys:

#Notice the command ends in ''
 sudo ssh-keygen -f /backup/ssh_key -t rsa -N ''

Updload keys:

#Port defaults to 22
ssh-copy-id <username>@<host> -p <port_nr>

If you do not have ssh-copy-id on your machine, you can either brew it or do the following:

Another alternative is to copy the public key file to the server and concatenate it onto the authorized_keys file manually. It is wise to back that up first:

cp authorized_keys authorized_keys_Backup
cat >> authorized_keys

Read more at Ubuntu's page