I’m not the best at scripting, but this should do the trick for anyone else using LVM and wanting to get full copies of the data.
The entire process of stopping and starting the axigen service was only seconds, so in theory, you could run this backup type nightly or a few times a day during downtime to keep more recent backups of your data. Overnight, lunchtime, end of day, etc.
This is perfect for a backup server sitting somewhere else to ensure continuity of servers in case of disaster.
Happy to take feedback on this as well in case people have better ideas on how this can be done. The important thing is that this is a snapshot of the server so you can bring up the disaster server knowing that all the data was copied from the snapshot while the server is running.
I would add this a cronjob on your production server. This was built against Debian 10, so your results may very if you’re using a different distro.
########################################################################################
#!/bin/bash
#You should only need to edit these variables:
#########################################
snapshot=colonysnap
axigenstore=/dev/vg_axigen/lv_data
axigensnap=/dev/vg_axigen/$snapshot
temp=/mnt/snapshot
username=root
remote=10.10.10.230
remotestore=/var/opt/axigen
#########################################
######DO NOT EDIT BELOW THIS LINE######
#Stop mail server
echo “stopping mail server” >> /var/log/syslog
/bin/systemctl stop axigen.service
echo “mail server stopped” >> /var/log/syslog
#Create snapshot
echo “creating temporary snapshot” >> /var/log/syslog
lvcreate -L 4096MB -s -n $snapshot $axigenstore
echo “snapshot created successfully” >> /var/log/syslog
#Start mail server
echo “starting mail server” >> /var/log/syslog
/bin/systemctl start axigen.service
echo “mail server started” >> /var/log/syslog
#Mount Snapshot
echo “making directory” >> /var/log/syslog
if [ -d “$temp” ]; then rm -Rf $temp; fi
mkdir $temp
echo “mounting snapshot” >> /var/log/syslog
mount $axigensnap $temp
echo “snapshot volumes mounted successfully” >> /var/log/syslog
#Start copy of snapshot data
echo “starting copy to remote server” >> /var/log/syslog
rsync -aHx --numeric-ids --progress --delete -e ‘ssh -T -c aes128-gcm@openssh.com -o Compression=no -x’ $temp $username@$remote:$remotestore
echo “data copy successfully completed” >> /var/log/syslog
#Unmount snapshot
echo “unmounting snapshot” >> /var/log/syslog
umount $temp
rm -rf $temp
#Remove Snapshot
echo “removing snapshot” >> /var/log/syslog
lvremove -y $axigensnap
echo “done” >> /var/log/syslog
########################################################################################