This document is a guide to backing up Abiquo. Every Abiquo installation is different so you must ensure that your backup configuration is appropriate for your installation. This guide gives a general explanation of which parts of Abiquo need to be backed up and how to do this manually and with Rsnapshot.
What to Back Up?
Abiquo Server, Remote Services and V2V
Save Abiquo directory
$ cp -R /opt/abiquo /path/to/backup/
Abiquo Server
Save MySQL data:
$ mysqldump kinton --routines --triggers > /path/to/backup/mysql/kinton-dump.sql $ mysqldump kinton_accounting --routines --triggers > /path/to/backup/mysql/kinton_accounting-dump.sql
Save Redis data:
$ redis-cli redis> SAVE redis> exit $ cp /var/lib/redis/dump.rdb /path/to/backup/redis
Abiquo Remote Services
Save DHCPD leases generated by Abiquo:
$ cp /var/lib/dhcpd/dhcpd.leases* /path/to/backup/dhcp
Save Redis data:
$ redis-cli redis> SAVE redis> exit $ cp /var/lib/redis/dump.rdb /path/to/backup/redis
Save /etc/fstab if you have made changes to the configuration since you installed Abiquo.
$ cp /etc/fstab /path/to/backup/fstab
Restore Abiquo Backups
Abiquo Server, Remote Services and V2V
Restore Abiquo properties:
$ cp /path/to/backup/abiquo/config/abiquo.properties /opt/abiquo/config/abiquo.properties
Abiquo Server
Restore MySQL data:
$ /etc/init.d/abiquo-tomcat stop $ mysql kinton < /path/to/backup/mysql/kinton-dump.sql $ mysql kinton_accounting < /path/to/backup/mysql/kinton_accounting-dump.sql $ /etc/init.d/abiquo-tomcat start
Restore Redis data:
$ /etc/init.d/redis stop $ cp /path/to/backup/redis/dump.rdb /var/lib/redis $ /etc/init.d/redis start
Abiquo Remote Services
Restore /etc/fstab configuration:
$ cp /path/to/backup/fstab /etc/fstab
Restore Redis data:
$ /etc/init.d/redis stop $ cp /path/to/backup/redis/dump.rdb /var/lib/redis $ /etc/init.d/redis start
Restore DHCPD leases:
$ /etc/init.d/dhcpd stop $ cp /path/to/backup/dhcp/dhcpd.leases* /var/lib/dhcpd/ $ /etc/init.d/dhcpd start
Restart Abiquo
Now you can restart the Abiquo Tomcat daemon:
$ service abiquo-tomcat restart
Configure a Remote Backup Server
Now we will describe how to configure a remote CentOS server to do the backups via rsnapshot. In this example we have an Abiquo Server (10.60.20.100) and an Abiquo Remote Services Server (10.60.20.101).
Prepare backup server
First of all, on the backup server, install RPMForge repositories (you can follow the CentOS RPMForge guide) and then install rsnapshot:
$ rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt $ wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm $ rpm -i rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm $ yum -y install rsnapshot
Create the directory where you want to store the backups:
$ mkdir /opt/backups
Generate SSH keys
We need to set up SSH passwordless keys in order to do backups automatically. Generate a pair of public/private keys on the backup server, leaving the passphrase empty:
$ ssh-keygen -t dsa Generating public/private dsa key pair. Enter file in which to save the key (/root/.ssh/id_dsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_dsa. Your public key has been saved in /root/.ssh/id_dsa.pub. The key fingerprint is:
Copy the public key to the host or hosts where you want to do the backup:
$ ssh-copy-id -i ~/.ssh/id_dsa.pub root@10.60.20.100 $ ssh-copy-id -i ~/.ssh/id_dsa.pub root@10.60.20.101
Install rsync
After you have successfully completed the above steps, you can install rsync on the target hosts:
$ ssh root@10.60.20.100 "yum -y install rsync" $ ssh root@10.60.20.101 "yum -y install rsync"
Configure rsnapshot
Elements in this file must be separated by tabs, and directories must end with a trailing slash '/'. Be careful of this if you do a copy & paste. You can split long lines by beginning a new line with a space or a tab character. All leading and trailing whitespace will be stripped off the new line, then it will be joined to the previous line with a tab character during configuration file parsing.
Edit /etc/rsnapshot.conf, and add the backup points that fit your needs. In our example:
snapshot_root /opt/backups/rsnapshots/ cmd_ssh /usr/bin/ssh interval hourly 6 interval daily 7 interval weekly 4 interval monthly 1 # Server backup root@10.60.20.100:/opt/abiquo/config/ abiquo-server/ backup root@10.60.20.100:/opt/abiquo/tomcat/conf/ abiquo-server/ backup root@10.60.20.100:/etc/ abiquo-server/ backup_script /opt/backups/backup_mysql.sh abiquo-server/mysql/ backup_script /opt/backups/backup_redis.sh abiquo-server/redis/ # Remote Services backup root@10.60.20.101:/opt/abiquo/config/ abiquo-rs/ backup root@10.60.20.101:/opt/abiquo/tomcat/conf/ abiquo-rs/ backup root@10.60.20.101:/var/lib/dhcpd/ abiquo-rs/ backup root@10.60.20.101:/etc/ abiquo-rs/ backup_script /opt/backups/backup_redis.sh abiquo-rs/redis/
As you can see in the configuration above, we use scripts in order to do MySQL and Redis dumps. The scripts are stored on the backup server. Put them under your /opt/backups/ directory, and modify the HOST variable to suit your needs:
#!/bin/bash HOST="10.60.20.100" MYSQL_DB="kinton" FILE=${MYSQL_DB}.$(date +"%Y%m%d-%H%M%S").sql.gz # dump the database and gzip it ssh root@${HOST} "mysqldump ${MYSQL_DB}" | gzip -9 > ${FILE}
#!/bin/bash HOST="10.60.20.101" REDIS_DUMP="/var/lib/redis/dump.rdb" FILE=dump.$(date +"%Y%m%d-%H%M%S").rdb.gz # dump the database and gzip it ssh root@${HOST} "redis-cli save" ssh root@${HOST} "cat ${REDIS_DUMP}" | gzip -9 > ${FILE}
Then make them executable:
$ chmod +x /opt/backups/*.sh
Setting up crontab
Automation is easily attainable using a simple crontab entry. Open /etc/crontab and add the following:
#MAILTO="" ##Supresses output MAILTO=me ################################################################### #minute (0-59), # #| hour (0-23), # #| | day of the month (1-31), # #| | | month of the year (1-12), # #| | | | day of the week (0-6 with 0=Sunday)# #| | | | | commands # ################################################################### 15 02 * * * /usr/bin/rsnapshot -c /etc/rsnapshot/laptop.rsnapshot.conf daily 15 03 * * Sun /usr/bin/rsnapshot -c /etc/rsnapshot/laptop.rsnapshot.conf weekly 30 03 1 * * /usr/bin/rsnapshot -c /etc/rsnapshot/laptop.rsnapshot.conf monthly
This setup runs a daily backup at 2:15am, a weekly backup on Sunday at 3:15am, and a monthly backup on the first of the month at 3:30am.