Categories
Fixing Stuff Samuel

Setting up and using rsync on 2 external machines

This post is just some notes as I learn how to utilize rsync between 2 servers that are on separate networks. rsync is ideally suited for this task because it will only transfer files that have changed instead of blindly transferring all files and wasting bandwith (which seems trivial but if you are using this to power website backups for example, that will mean the difference of transferring your entire site vs transferring only files that have been changed)

1.) Create your rsync shell script, example script below:
rsync -avz /path/to/back/up/files/on/server/ username@host.com:/path/on/your/backup/machine/

2.) Upload the file to the machine that you will be pushing from (make sure to make it executable by running chmod +x on the file after uploading it)

3.) SSH into the machine and test the command by running ./filename

If all goes well your machine will connect and if its the first time it will ask you to verify the fingerprint of the external machine, type yes and hit enter. Your off to the races, to automate this script simply create a cron job to execute the shell script at whatever interval you like.

Troubleshooting:

If you are having trouble establishing the connection here are some things to try:

1.) make sure you are using the correct port (22 is the default ssh port, but its a good idea to not use this port for added security so if you need to add another port then update your command to:
rsync -avz -e 'ssh -p port#' /path/to/back/up/files/on/server/ user@host.com:/path/on/your/backup/machine/

2.) If your connection is timing out you can test it by running:
ssh user@host.com -p port#

or by running

telnet host.com port#

If both of these test connections are displaying time out errors to you, then there is a firewall issue on your host machine preventing the connection from routing correctly to your backup machine.

3.) If you can’t get the script to connect, just try to manually SSH into the external machine first. You will either run into the improper port being open, or the SSH auth is not allowed in freenas on the machine.

Troubleshoting the actual rsync:

1.) If the rsync command generates a weird folder on the external machine do ________
2.) If the rsync command won’t sync files from the external machine onto the local machine do _______