Backup

Some web hosting service providers allow ssh access to Linux shared servers. That allows one to backup their data more easily using the rsync tool. The following is a simple yet fully functional example of a shell script that syncs the data from the remote server to a local destination. All you need to do is:

  • find out what Linux OS is installed on the remote shared location (usually Enterprise Linux OS’s such as RHEL/CentOS). Assuming the server runs a RHEL-like operating system, you need to find the OS version and architecture:

 

Run this on the remote server:
cat /etc/*release*
uname -m
echo $PATH
rpm -q rsync (most likely will return nothing e.g. rsync is not installed)

 

  • download an rsync binary to put in your $HOME dir on the server (in $PATH or any other folder) e.g.:

 

Run this on your local machine:
wget http://pkgs.repoforge.org/rsync/rsync-3.0.8-1.el6.rfx.x86_64.rpm
rpm2cpio rsync-3.0.8-1.el6.rfx.x86_64.rpm | cpio -idmv
scp usr/bin/rsync remote_server:~/bin

 

Sample shell script (to be executed on your local machine):

#!/bin/bash
ARGS="-azHhv --ignore-errors --stats --partial --rsync-path=~/bin/rsync"
SSH_USER=user_account
SERVER=server_name
LOG_FILE=backup.log
rsync $ARGS -e "ssh -l $SSH_USER" $SERVER:~ ~/backup/ > $LOG_FILE 2>&1
if [ $? -eq 0 ];
   then printf "\nNo errors, all OK!" >> $LOG_FILE
   else printf "\nErrors found, check log file!" >> $LOG_FILE
fi

 

Simply modify the script with your details: user name, server name, remote path on the server (the default is ~), the local path to store the backup (default is ~/backup), the path where you copied the rsync binary (default is ~/bin) and it is ready to use.