Rsync is an excellent file transfer utility thats especially well suited for backing up files over the Internet because it only transfers the data that has changed. A friend asked me how to set it up, so I thought I’d post what I sent him here.
Goal: Backup a directory from computer
Zim to computer
Arkare subdomains of
- The user on
Arkwhich receives the backup files is named
- The user on
Zimwith access to the files you want to backup is named
sshkey pair using:
ssh-keygen -t rsa <press enter when prompted where to save the key> <press enter twice when asked for a passphrase>
To use the key to login to
Arkremotely without manually entering a password you need to copy the public key from
ssh-copy-id -i .ssh/id_rsa.pub firstname.lastname@example.org
If you don’t have
ssh-copy-idon your system, get a new system. 😉 If thats not possible you can download the script with:
wget -O ssh-copy-id http://cvsweb.mindrot.org/index.cgi/~checkout~/openssh/contrib/ssh-copy-id?rev=1.6;content-type=text%2Fplain && chmod +x ssh-copy-id
Then retry the above command only you’ll need to prepend a “./”:
./ssh-copy-id -i .ssh/id_rsa.pub email@example.com
Verify the key copied properly by attempting to login to
Ark. You should not be prompted for a password:
Ark. The key is setup, so you’re now ready to rsync files without having to manually enter a password.
Test rsync by choosing a small file to backup and using:
rsync -tP /some/small/testfile firstname.lastname@example.org:/tmp
A nice little progress bar should be displayed as the file is transferred. Confirm that “testfile” is now in
You’re finally ready to do a real rsync like:
rsync -t /directory/to/backup/* email@example.com:/existing/backup/directory
Note: There are several useful options for rsync. Check
man rsyncto find out more.
-p— preserve permissions (useful for backups, use -E if you only care about the executable bit)
-r— recursively backup directories.
-z— compressed uncompressed files
- And just FYI:
-ttells rsync to use the last modified timestamp to determine whether or not to transfer files. It makes rsync a lot faster at determining whether or not files have changed.
To schedule the backup to take place nightly at 1:13 AM edit your crontab using
crontab -eand insert the following line:
13 1 * * * rsync -qt /directory/to/backup/* firstname.lastname@example.org:/existing/backup/directory
- These instructions will push files from
Ark. There’s no reason why
Arkcouldn’t pull files from
Zim. In fact, this is often more secure if
Zimis a web server with a larger attack surface than
Ark. Mea culpa.
- If the IP address of
Arkis dynamic, use a service like dyndns.com. Otherwise SSH will give you errors.
- Major security warning: If someone breaks into
Zim, they can also delete all of your backups on
Ark. Never ever ever use the
rootuser for backups on
Ark. You can use the
Zimto send the backups, but its best to have a special backup user setup on
Arkto receive the backup.