How To : Setup Remote Backup for IPS1 Linux Shared Hosting

  Tools

For all Linux Shared Hosting, backup stored in different server. Rsnapshot been used to generate the backup, as it using rsync to transfer the data from Shared Hosting to backup server.

For example below, we will be setting up remote backup for NS72 in backup server, 210.5.44.158. We start with SSH to the backup server and follow the following steps,

cd /usr/local/src
wget http://rsnapshot.org/downloads/rsnapshot-1.4.2.tar.gz
tar xvf rsnapshot-1.4.2.tar.gz
cd rsnapshot-1.4.2
./configure
make && make install

We will be customizing the default config of rsnapshot. Run the following commands,

echo -e "config_version\t1.2" > /etc/rsnapshot-common.conf
echo -e "cmd_cp\t\t/bin/cp" >> /etc/rsnapshot-common.conf
echo -e "cmd_rm\t\t/bin/rm" >> /etc/rsnapshot-common.conf
echo -e "cmd_rsync\t/usr/bin/rsync" >> /etc/rsnapshot-common.conf
echo -e "cmd_ssh\t\t/usr/bin/ssh" >> /etc/rsnapshot-common.conf
echo -e "cmd_logger\t/bin/logger" >> /etc/rsnapshot-common.conf
echo -e "verbose\t\t4" >> /etc/rsnapshot-common.conf
echo -e "loglevel\t4" >> /etc/rsnapshot-common.conf
echo -e "ssh_args\t-p 9321" >> /etc/rsnapshot-common.conf
echo -e "exclude\t\t*.tar.gz*" >> /etc/rsnapshot-common.conf
echo -e "exclude\t\t*.iso" >> /etc/rsnapshot-common.conf
echo -e "exclude\t\t*.zip" >> /etc/rsnapshot-common.conf
echo -e "sync_first\t1" >> /etc/rsnapshot-common.conf

rsnapshot-common.conf will be generated in /etc, and the config should as below,

cat /etc/rsnapshot-common.conf
config_version	1.2
cmd_cp		/bin/cp
cmd_rm		/bin/rm
cmd_rsync	/usr/bin/rsync
cmd_ssh		/usr/bin/ssh
cmd_logger	/bin/logger
verbose		4
loglevel	4
ssh_args	-p 9321
exclude		*.tar.gz*
exclude		*.iso
exclude		*.zip
sync_first	1

Backup that generated, will be stored in different partition. Base on partition below, NS72 backup will be stored in /disk01.

[root@backup-44-158 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        99G  1.8G   92G   2% /
devtmpfs        3.8G     0  3.8G   0% /dev
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           3.9G  8.6M  3.8G   1% /run
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           779M     0  779M   0% /run/user/0
/dev/md0        7.3T   93M  6.9T   1% /disk01
/dev/md1        7.3T   93M  6.9T   1% /disk02
/dev/md2        7.3T   93M  6.9T   1% /disk03

Next, we will create a new folder for client (NS72) and create a symbolic link from /home to NS72 folder that been created.

[root@backup-44-158 ~]# cd /disk01
[root@backup-44-158 disk01]# mkdir ns72
[root@backup-44-158 disk01]# cd /home
[root@backup-44-158 home]# ln -s /disk01/ns72 ns72

The output should as below,

[root@backup-44-158 home]# ls -al
total 12
drwxr-xr-x.  3 root     root     4096 Oct 14 15:03 .
dr-xr-xr-x. 22 root     root     4096 Oct 14 14:16 ..
drwx------.  2 isupport isupport 4096 Oct 14 13:37 isupport
lrwxrwxrwx.  1 root     root       12 Oct 14 15:03 ns72 -> /disk01/ns72

Each client has their own backup config. For example, we will generate client (NS72) config, run the following commands,

echo -e "include_conf\t/etc/rsnapshot-common.conf" > /home/ns72/ns72.conf
echo -e "snapshot_root\t/home/ns72/" >> /home/ns72/ns72.conf
echo -e "interval\tdaily\t7" >> /home/ns72/ns72.conf
echo -e "logfile\t\t/home/ns72/rsnapshot.log" >> /home/ns72/ns72.conf
echo -e "lockfile\t/home/ns72/rsnapshot.pid" >> /home/ns72/ns72.conf
echo -e "exclude_file\t/home/ns72/excluded.list" >> /home/ns72/ns72.conf
echo -e "rsync_long_args\t--compress --recursive --times --perms --links --owner --group --delete --numeric-ids --relative --delete-excluded --rsync-path=/usr/bin/rsync" >> /home/ns72/ns72.conf
echo -e "backup\t\tibackup@192.168.192.72:/etc\t\t\t./" >> /home/ns72/ns72.conf
echo -e "backup\t\tibackup@192.168.192.72:/usr/local/directadmin\t./" >> /home/ns72/ns72.conf
echo -e "backup\t\tibackup@192.168.192.72:/var/www/html\t\t./" >> /home/ns72/ns72.conf
echo -e "backup\t\tibackup@192.168.192.72:/var/named\t\t./" >> /home/ns72/ns72.conf
echo -e "backup\t\tibackup@192.168.192.72:/home\t\t\t./" >> /home/ns72/ns72.conf
mkdir /home/ns72/.sync
touch /home/ns72/excluded.list

Please take note the directory, client name and client private ip address. Change it accordingly base on the client you like to configure.

Now we need to copy the backup server rsa public key and add it in the client (NS72).

[root@backup-44-158 ~]#  cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDB9Gg5ToKjYHfSTOSjGKgdmppi7WM3FoQy7RI1ZjhlA3rHVja2ClDx98mpigQSomZMcIHZdU4zDnbqIW742iuf/usd8VlfGmwE5Koq7ispp8/zG7yk6m4332XBjfM/EOCz2RD3EMZ3Yeea7WQfiCzQrriab/rOP3DUbY1R/KORTC1Fso+dlUdiM1gWfe88kepv7ykodM0T/UQkbvjJEQaweTb+f+htUa9J+4i92OMXFk/7qnbih8P9rDuhEfMe381UIfC9p19qfAW78F77ydlfxdqBdjvrDJYby6XuY2T9eYOaRpRffiZG5sCGkbOc5NlKgi/XkpLIP4eEadCxTVj0odF//gG1ZAdE1ElwR4q/LN2xNbJ6oo9Y3OI7H4SBu74GXlCEMQEqvPx3yE2HF15GIvXNPRl9RN1OxDjvuFQV/UJ4vc3pdWC/vzg9kza0zadxGt4gchaHZLd6uLcvlPcA1F7hrAv2Kr1RkiMzbVd9M5rzE/pfUkTQHuTf+HcvFVNMy4KkjyJv/kzbRPKmAKJw3VjrU5/m17AVPWT8qKCUqXl3TZ885F+GVhQRiXZtwMNPD+fmSb0Ggw6o3ItX9ntGhtEtKBkqLjE2UVf5WGz4s0Td26zvcMQZGiITy7pZ+B9KHMSDxv840xvBBa64qno7RKEY9m1Kuip5r+wtBCIdcw== root@backup-44-158.small.dns.com

Create a new backup script ips1-smartBackup-ns72.sh. Copy the script from http://knowledge.asyraf.my/rsnapshot-remote-backup-script/