59 lines
1.7 KiB
Bash
59 lines
1.7 KiB
Bash
|
|
function prepare_backup_disk {
|
|
|
|
## Bit from the rsync script that does some sanity checks and set up Data Store backups if present
|
|
check_config_var "CONFLUENCE_BACKUP_HOME"
|
|
check_config_var "CONFLUENCE_HOME"
|
|
|
|
# CONFLUENCE_RESTORE_DATA_STORES needs to be set if any data stores are configured
|
|
if [ -n "${CONFLUENCE_DATA_STORES}" ]; then
|
|
check_var "CONFLUENCE_BACKUP_DATA_STORES"
|
|
fi
|
|
##
|
|
|
|
# Confirm there are no existing snapshots, exit if present
|
|
|
|
if [ $(lvs | grep -ic snap) -gt 0 ]; then
|
|
echo "Snapshot already exists. Stopping backup"
|
|
exit
|
|
fi
|
|
}
|
|
|
|
function backup_disk {
|
|
|
|
# take lvm snapshot for backup
|
|
volume=$(df | grep data1 | cut -d" " -f1)
|
|
snapshot_name=snapbackup_$(date +"%m-%d_%H%M")
|
|
|
|
lvcreate --size 4G --snapshot --name $snapshot_name $volume
|
|
|
|
# Mount snapshot before rsync
|
|
vg=$(lvs | grep $snapshot_name | cut -d" " -f4)
|
|
snap_volume=/dev/$vg/$snapshot_name
|
|
|
|
mount -onouuid,ro $snap_volume ${CONFLUENCE_HOME_SNAP}
|
|
|
|
# Create new variable to define source of backup as snapshot
|
|
# CONFLUENCE_HOME_SNAP=/data2/snapshot/CONFLUENCE-home/
|
|
|
|
# rsync home from snapshot
|
|
# perform_rsync_home_directory
|
|
# perform_rsync_data_stores
|
|
perform_compress_data
|
|
perform_rsync_compress_data
|
|
|
|
# unmount and remove lvm snapshot
|
|
umount ${CONFLUENCE_HOME_SNAP}
|
|
lvremove -f $snap_volume
|
|
}
|
|
|
|
function perform_compress_data {
|
|
day_new_format=$(date +%Y-%m-%d)
|
|
tar -czPf $CONFLUENCE_TMP/$day_new_format.tgz $CONFLUENCE_HOME_SNAP
|
|
}
|
|
|
|
function perform_rsync_compress_data {
|
|
rsync --remove-source-files -h $CONFLUENCE_TMP/$day_new_format.tgz $CONFLUENCE_BACKUP_HOME/
|
|
}
|
|
|