sudo yum -y --enablerepo=base --enablerepo=updates --enablerepo=extras --enablerepo=base --enablerepo=centosplus install epel-release
sudo yum -y --enablerepo=base --enablerepo=updates --enablerepo=extras --enablerepo=base --enablerepo=centosplus install autossh
ssh-keygen
(just keep hitting enter, accept the default values)
ssh-copy-id xbackup@xenstorage2.gvoperations.com
Existing file
vim /etc/rc.local
# Add this line into the file
autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/user/.ssh/id_rsa.pub -L 3049:localhost:2049 xbackup@xenstorage2.gvoperations.com
New file
# vi /etc/systemd/system/rc-local.service
# Add these lines
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
chmod +x /etc/rc.d/rc.local
sudo systemctl start rc-local
sudo systemctl enable rc-local
sudo systemctl status rc-local
ps auxf | grep autossh
You should see: autossh -M 10984 -N -o PubkeyAuthentication=yes -o PasswordAuthentication=no -i /home/user/.ssh/id_rsa.pub -L 3049:localhost:2049 xbackup@xenstorage2.gvoperations.com
mkdir -p /mnt/nfs/data
This should mount the data share under /mnt/nfs/data in 30 seconds or less
mount -t nfs -o port=3049 localhost:/mnt/data /mnt/nfs/data
cd /opt
wget https://github.com/NAUbackup/VmBackup/archive/master.zip
unzip master.zip
rm -fv master.zip
New file
vi /opt/backup.sh
Append this contents:
#!/usr/bin/bash
# Jonathan Kelley :: Feb, 2, 2018
# Check if NFS is currently mounted
PATH=/opt/xensource/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
/usr/bin/mount | /usr/bin/grep 'localhost:/mnt/data on /mnt/nfs/data' > /dev/null 2>&1
if [ $? -eq 0 ]
then
/usr/bin/echo "NFS is already mounted, OK."
else
/usr/bin/echo "NFS not mounted, mounting filesystem."
/usr/bin/mount -t nfs -o port=3049 localhost:/mnt/data /mnt/nfs/data
fi
# Parse the configurations
case "$1" in
"daily")
/opt/VmBackup-master/VmBackup.py /root/VmBackup.pass /opt/VmBackup-master/daily.cfg
;;
"biweekly")
/opt/VmBackup-master/VmBackup.py /root/VmBackup.pass /opt/VmBackup-master/biweekly.cfg
;;
"weekly")
/opt/VmBackup-master/VmBackup.py /root/VmBackup.pass /opt/VmBackup-master/weekly.cfg
;;
"monthly")
/opt/VmBackup-master/VmBackup.py /root/VmBackup.pass /opt/VmBackup-master/monthly.cfg
;;
*)
/usr/bin/echo "Error : You must specify daily, biweekly, weekly, or monthly as your first arguement"
exit 1
;;
esac
/usr/bin/umount /mnt/nfs/data
Change permission to executable
chmod 755 /opt/backup.sh
chmod 755 /opt/VmBackup-master/VmBackup.py
Change existing file /etc/crontab
vim /etc/crontab
Contents
31 15 * * * /opt/backup.sh daily
30 2 * * 1,5 /opt/backup.sh biweekly
30 8 * * 3 /opt/backup.sh weekly
1 3 1 * * /opt/backup.sh monthly
Now we will setup the configurations
Replace password in the single quotes with your Xen console password. This is used to export the images over Xen API. This step needs to be re-run every time the root passwords change.
/opt/VmBackup-master/VmBackup.py 'ROOT PASSWORD' create-password-file=/root/VmBackup.pass
NOTE This is MASTERS hypervisor password. Re-run this with a new password if the hypervisor password changes, otherwise backups will stop.
cd /opt/VmBackup-master/
vi biweekly.cfg
# File contents in this gist (below)
vi daily.cfg
# File contents in this gist (below)
vi monthly.cfg
# File contents in this gist (below)
vi weekly.cfg
# IMPORTANT! IMPORTANT! ADVISIO!
# Please update the variables in each config file.
# EXAMPLE:
# backup_dir=/mnt/nfs/data/hydra-p1
# status_log=/mnt/nfs/data/hydra-p1.log
If you see any results, those files still need to be updated with current POOL NAME
grep -i hydra *.cfg
mkdir -p $(grep backup_dir daily.cfg | cut -d"=" -f2)
Every guest VM needs a name to get backups. This is a 'tag' in the name which tells the backup script to do the job.
BUDAILY-servername
BUWEEKLY-servername
BUBIWEEK-servername
BUMONTHLY-servername