diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/hydra/backup | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/hydra/backup b/lib/hydra/backup new file mode 100644 index 0000000..17f7349 --- /dev/null +++ b/lib/hydra/backup @@ -0,0 +1,51 @@ +#!/bin/bash + +# Setup backup environment +function hydra_backup_environment { + NODE="$1" + METHOD="$2" + BACKUP_ROOT="/var/backups/remote" + DOMAIN="`facter domain`" + BACKUPDIR="$BACKUP_ROOT/$NODE.$domain" + RESTOREDIR="$BACKUPDIR/restore/`date +%Y%m%d`" + + if [ -z "$NODE" ]; then + hydra_action_usage + exit 1 + fi + + if [ ! -d "$BACKUPDIR" ]; then + echo "No backup found at $BACKUPDIR" + exit 1 + fi + + if [ -z "$METHOD" ]; then + if [ -d "$BACKUPDIR/rsync" ]; then + echo "Assuming rsync backup method" + BACKUPDIR="$BACKUPDIR/rsync" + elif [ -d "$BACKUPDIR/rdiff" ]; then + echo "Assuming rdiff backup method" + BACKUPDIR="$BACKUPDIR/rdiff" + else + echo "Missing backup action" + exit 1 + fi + else + if [ "$METHOD" == "restore" ]; + echo "Invalid backup method 'restore'" + exit 1 + elif [ -d "$BACKUPDIR/$METHOD" ]; then + BACKUPDIR="$BACKUPDIR/$METHOD" + else + echo "Backup folder for $METHOD not found at $BACKUPDIR" + exit 1 + fi + fi + + if [ -d "$RESTOREDIR" ]; then + echo "Restoration folder $RESTOREDIR already exists" + exit 1 + fi + + mkdir -p $RESTOREDIR +} |