diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2011-09-27 14:45:36 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2011-09-27 14:45:36 -0300 |
commit | 1f25194c5ab63ee588fa66f09cf30f5994490455 (patch) | |
tree | fac630f43fb1c5e488f24a50f9839d7c6160e6da /lib | |
parent | 402782207daaea438316c4ef9b38f3e5198beb03 (diff) | |
download | hydra-1f25194c5ab63ee588fa66f09cf30f5994490455.tar.gz hydra-1f25194c5ab63ee588fa66f09cf30f5994490455.tar.bz2 |
Renaming actions and adding backup function
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 +} |