Incremental Backup Script
These are the backup scripts that I used to back up any Linux servers to my local machine. First thing that you should do is set-up the SSH keys so you can connect to your local machine without the need of a password.
On the Remote host you need to generate the keys with the following command:
ssh-keygen -t rsa
When you are asked for a pass phrase just hit enter twice. Now you should copy the key you have just generated over to your local machine:
scp .ssh/id_rsa.pub username@host:.ssh/authorized_keys2
Just replace the username with the local machine user and the host with the IP Address or hostname of the local machine. After the key has copied over you should now be able to connect from the remote host to the local machine without entering a password.
Now for setting up the backup script
You can download the script from Here.
You need to change a few lines in the script. Change the variable REMOTE to match the server you will backup the information too. The variable name BACKUP_DIR is the folder on the remote machine that the backup will be stored. DIRS is a list of the local machines folders you want to backup. You will also want to change the email address.
For Example: I want to backup the folders /etc and /home using the username jay on the remote server backup.jayscott.co.uk within /home/jay/backup, then all alerts sent to jay@jayscott.co.uk so I would have the following:
REMOTE=”jay@backup.jayscott.co.uk”
BACKUP_DIR=”backup”
DIRS=”/etc /home”
EMAIL=”jay@jayscott.co.uk”
Copy the script to /sbin/remotebackup and chmod it:
chmod 700 /sbin/remotebackup
You can run the script manually or you can add the backup to the cron with the following:
01 0 * * * /sbin/remotebackup > /var/log/remote_backup.log
This will run the script every day at 1 minute past midnight. If you changed the LOGFILE variable in the script, make sure you change the above line to reflect it.