[How to] [Ubuntu] Send backup files to remote server using rsync
02-06-2015, 08:08 PM
(This post was last modified: 02-06-2015, 08:09 PM by Diablo925.)
First we need to make a RSA key to the remote server
STEP 1
STEP 2
Once you have entered the Gen Key command, you will get a few more questions:
You can press enter here, saving the file to the user home (in this case, my example user is called demo).
Step 3
Now we copy the rsa key to the remote server
Now we test if is works
If you don’t need to enter password it Works
Now the Rsync script
Step 1
Add this
If you add --remove-source-files in OPTIONS it delete the files after upload on source server
SETP 2
Add crontab
Add the line
This will at the script at midnight
STEP 1
Code:
ssh-keygen -t rsa
STEP 2
Once you have entered the Gen Key command, you will get a few more questions:
Code:
Enter file in which to save the key (/home/demo/.ssh/id_rsa):
You can press enter here, saving the file to the user home (in this case, my example user is called demo).
Code:
Enter passphrase (empty for no passphrase):
Step 3
Now we copy the rsa key to the remote server
Code:
ssh-copy-id root@111.222.333.444
Now we test if is works
Code:
SSH root@111.222.333.444
Now the Rsync script
Step 1
Code:
Nano /var/script/backup.sh
Add this
Code:
#!/bin/bash
###############################
# Some settings
###############################
# rsync options
DEST=root@111.222.333.444:/patch/to/the/folder/to/save/files/ SRC=/var/sentora/hostdata/*
OPTIONS="-e ssh --delete --progress -azvhHS --numeric-ids --delete-excluded"
EXCLUSIONS=" --exclude public_html"
###############################
# The real work
###############################
# Do the actual backup
rsync $OPTIONS $EXCLUSIONS $SRC $DEST
If you add --remove-source-files in OPTIONS it delete the files after upload on source server
SETP 2
Add crontab
Code:
Crontab –e
Add the line
Code:
@daily bash /var/script/backup.sh
This will at the script at midnight