Goal: backup directory from computer Zim to computer Ark
Details:
- Both Zim and Ark are subdomains of example.com
- The user on Ark which receives the backup files is named backupuser
Prerequisites:
- ssh installed on both hosts
- rsync installed on both hosts
1. Login to Zim via ssh
2. Generate ssh key pair using:
ssh-keygen
<press enter when prompted where to save the key>
<press enter twice when asked for a passphrase>
3. To use the key to login to Ark remotely without manually entering a password you need to copy the public key from Zim to Ark using:
ssh-copy-id -i .ssh/id_rsa backupuser@ark.example.com
4. Verify the key copied properly by attempting to login. You should not be prompted for a password:
ssh backupuser@ark.example.com
5. Logout of ark. The key is setup, so you're now ready to rsync files without having to manually enter a password.
6. Test rsync by choosing a small file to backup and using:
rsync -P /some/small/testfile backupuser@ark.example.com:/tmp
A nice little progress bar should be displayed as the file is transferred. Confirm that "testfile" is now in /tmp on Ark.
7. You're finally ready to do a real rsync like:
rsync /directory/to/backup/* backupuser@ark.example.com:/existing/backup/directory
Note: use add "-r" after rsync to recursively backup directories.
8. To schedule the backup to take place nightly at 1:13 AM edit your crontab using `crontab -e` and insert the following line:
13 1 * * * rsync /directory/to/backup/* backupuser@ark.example.com:/existing/backup/directory
rsync is extremely powerful and relatively easy to use, so don't be afraid to check out `man rsync` for more details.
Caveats:
- If the IP address of Ark is dynamic, use a service like dyndns.com. Otherwise SSH will give you errors.
- Major security problem: If someone breaks into Zim, they can also delete all of your backups on Ark. Never ever ever use the `root` user for backups on Ark. You can use the `root` user on Zim to send the backups, but its best to have a special backup user setup on Ark to receive the backup.