#!/bin/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 ## # Create Mount point if it is not already exists; if [ ! -d "${CONFLUENCE_HOME_SNAP}" ]; then mkdir -p ${CONFLUENCE_HOME_SNAP} 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} 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/ } function prepare_restore_disk { check_var "CONFLUENCE_RESTORE_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_RESTORE_DATA_STORES" fi # Check CONFLUENCE_HOME and CONFLUENCE_DATA_STORES are empty ensure_empty_directory "${CONFLUENCE_HOME}" for data_store in "${CONFLUENCE_DATA_STORES[@]}"; do ensure_empty_directory "${data_store}" done # Create CONFLUENCE_HOME and CONFLUENCE_DATA_STORES check_config_var "CONFLUENCE_UID" check_config_var "CONFLUENCE_GID" run mkdir -p "${CONFLUENCE_HOME}" run chown "${CONFLUENCE_UID}":"${CONFLUENCE_GID}" "${CONFLUENCE_HOME}" for data_store in "${CONFLUENCE_DATA_STORES[@]}"; do run mkdir -p "${data_store}" run chown "${CONFLUENCE_UID}":"${CONFLUENCE_GID}" "${data_store}" done } function restore_disk { local rsync_quiet=-q if [ "${CONFLUENCE_VERBOSE_BACKUP}" = "true" ]; then rsync_quiet= fi run rsync -av ${rsync_quiet} "${CONFLUENCE_RESTORE_HOME}/" "${CONFLUENCE_HOME}/" for data_store in "${CONFLUENCE_DATA_STORES[@]}"; do run rsync -av ${rsync_quiet} "${CONFLUENCE_RESTORE_DATA_STORES}/${data_store}" "${data_store}/" done } function cleanup_incomplete_disk_backup { no_op } function cleanup_old_disk_backups { no_op }