Remote Data Backup - Users Guide
Rsync for LINUX (Red Hat)
INSTRUCTIONS TO SETUP KEYS (optional)
As the user you are going to be running rsync as, and on the machine you will be running rsync on, type:
ssh-keygen -t rsaFollow the prompts and use the defaults for the filenames it gives you. Don't enter in a passphrase. You should then have two new files in ~/.ssh, id_rsa and id_rsa.pub.
Now, upload the newly created key to your account with this command:
scp -P SSH_PORT# ~/.ssh/id_rsa.pub USERANME@HOSTNAME:.ssh/authorized_keys
Note: The directory ".ssh" must have permission set to 0700, and the file "authorized_keys" must have permissions set to "0600" bofore the key to work. To check or change permissions, login with WinSCP, right click the file or directory, choose 'Propeties', and under 'Permissions' change them as needed.
Backing Up Files
At the command prompt type the following command:
rsync -avr -e 'ssh -p SSH_PORT# -i ~.ssh/id_rsa' files-to-backup USERNAME @HOSTNAME:backups
The "-avr" of the command stands for:
- a: archive, preserves all attributes like ownership, timestamps, etc
- v: verbose output
- r: recursive, recurse into directories
Extra Rsync Command Line Options
Add any of these commands after the '-avr' command. You may include as many of these commands as you want.
This will delete files remotely that no longer exist locally.
This will exclude all files having the jpg extension
This will include files having the jpg extension
Shows you the progress of all the files that are being synced
Shows what would have been transferred, but does not transfer anything
Automate with Cron
Create a batch file as shown below by using a text editor:
rsync -avr -e 'ssh -p SSH_PORT# -i ~.ssh/id_rsa' FILES-TO-BACKUP USERNAME @HOSTNAME:backups
Save the file as "backup.sh".
Change permissions of "backup.sh" to 0755.
Create a cron job to run the shell script at a specific time (7 pm, on every day). Example below.
0 19 * * * ./path-to-shell-script/backup.sh