#!/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 ## # 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 50G --snapshot --name $snapshot_name $volume # Mount snapshot before rsync vg=$(lvs | grep $snapshot_name | cut -d" " -f5) snap_volume=/dev/$vg/$snapshot_name mount -onouuid,ro $snap_volume /data1/snapshot # Create new variable to define source of backup as snapshot CONFLUENCE_HOME_SNAP=/data1/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 /data1/snapshot lvremove -f $snap_volume } ## Functions copied from the rsync script since we are essentially using rsync but utilizing an lvm snap as the source ## instead. Changed CONFLUENCE_HOME to CONFLUENCE_HOME_SNAP where appropriate and tagged each change in case we ever ## need to redo. We still want restores to work the same(from the archive file) so no changes there only on the ## backup rsyncs - JM function perform_compress_data { # Globals backupDir="/jira-wiki-backup/confluence" pgdump="pg_dump" # Backup target directories backupDirDaily="$backupDir/$day_new_format" day_new_format=$(date +%Y-%m-%d) tar -czPf $backupDirDaily/$day_new_format.tgz /data1/snapshot } function perform_rsync_compress_data { rsync avh --progress $backupDirDaily/$day_new_format.tgz /backup/confluence } 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 }