]> gitweb.fluxo.info Git - hydra.git/commitdiff
Adding backup/copy sites; restoration fixes
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 4 Jan 2012 20:43:33 +0000 (18:43 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 4 Jan 2012 20:43:33 +0000 (18:43 -0200)
lib/hydra/backup
share/hydra/deploy
share/hydractl/backup-copy-site [new file with mode: 0755]
share/hydractl/backup-copy-sites [new file with mode: 0755]
share/hydractl/backup-restore
share/hydractl/backup-restore-gitosis
share/hydractl/backup-restore-site
share/hydractl/backup-restore-svn
share/hydractl/backup-site
share/hydractl/backup-sites [new file with mode: 0755]

index 9c35ff95dbee1a71292b4fd308329cf13793115a..e3edf509963d28b69d75608419b11885df642aed 100644 (file)
@@ -2,10 +2,11 @@
 
 # Setup environment for the backups website
 function hydra_backup_environment_local_website {
-  SITE="$1"
-  BACKUPDIR="/var/sites/backups/site/$SITE"
+  NODE="$1"
+  SITE="$2"
+  BACKUPDIR="/var/sites/backups/site/$SITE/$NODE"
 
-  if [ -z "$SITE" ]; then
+  if [ -z "$SITE" ] || [ -z "$NODE" ]; then
     hydra_action_usage
     exit 1
   fi
@@ -61,10 +62,10 @@ function hydra_backup_environment_remote {
   if [ -z "$METHOD" ]; then
     if [ -d "$BACKUPDIR/rsync" ]; then
       echo "Assuming rsync backup method"
-      BACKUPDIR="$BACKUPDIR/rsync"
+      BACKUPDIR="$BACKUPDIR/rsync/var/backups/duplicity/daily.1"
     elif [ -d "$BACKUPDIR/rdiff" ]; then
       echo "Assuming rdiff backup method"
-      BACKUPDIR="$BACKUPDIR/rdiff"
+      BACKUPDIR="$BACKUPDIR/rdiff/var/backups/duplicity"
     else
       echo "Missing backup action"
       exit 1 
index 0a8a5deb84098f7d2b32e5bb98b816f61aa2b0b6..561e675bdfeaf270b99c515bc2ae10e38e3a0f3c 100755 (executable)
@@ -9,7 +9,7 @@ hydra_config_load
 
 # Command line arguments
 NODES="$*"
-COMMIT="f360acf0fab1d941bc7de8bec3d22aabd64f49fe"
+COMMIT="26cbb26cebd495fd6260b6af65b37fe5c8a8c00b"
 
 # Build node list
 if [ -z "$NODES" ]; then
diff --git a/share/hydractl/backup-copy-site b/share/hydractl/backup-copy-site
new file mode 100755 (executable)
index 0000000..d64ac7e
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/bash
+#
+# Copy a site backup between servers.
+#
+
+# Load.
+source $APP_BASE/lib/hydra/functions || exit 1
+hydra_config_load
+
+# TODO
+# Basic parameters.
+# Syntax check.
+# Parse server name and port.
+# Check restore strategy.
+# Sync to remote destination.
diff --git a/share/hydractl/backup-copy-sites b/share/hydractl/backup-copy-sites
new file mode 100755 (executable)
index 0000000..19b41d1
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+#
+# Copy multiple sites.
+#
+
+# Basic parameters.
+SERVER="$1"
+
+# Syntax check.
+if [ -z "$SITE" ]; then
+  hydra_action_usage
+  exit 1
+fi
+
+# Determine sites to copy.
+if [ -z "$2" ]; then
+  sites="`ls /var/sites`"
+else
+  shift
+  sites="$*"
+fi
+
+# Copy each site.
+for site in $sites; do
+  hydractl backup-copy-site $SERVER $site
+done
index a5bfd42c1f34b6836ef44ecb4095cdf77bc3d641..438d1a648a5d567d5e8c87f6b703c619bfc28989 100755 (executable)
@@ -7,11 +7,17 @@
 source $APP_BASE/lib/hydra/functions || exit 1
 hydra_config_load
 
+# Syntax check.
+if [ -z "$1" ]; then
+  echo "Usage: `basename $0` <localhost|server> [rsync|rdiff]"
+  exit 1
+fi
+
 # Check restore strategy.
 if [ "$1" == "localhost" ]; then
-  hydra_backup_environment_local $2 restore
+  hydra_backup_environment_local
 else
-  hydra_backup_environment_remote $1 restore
+  hydra_backup_environment_remote $*
 fi
 
 duplicity restore file:///$BACKUPDIR/ $RESTOREDIR/
index f569a8e744210d4f7aba493cd38d102b48087671..f8b9ea36d669a89e338cc268efe0a87d5f1ffb98 100755 (executable)
@@ -12,7 +12,7 @@ DATE="`date +%Y%m%d`"
 
 # Check restore strategy.
 if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
-  hydra_backup_environment_local $2 restore
+  hydra_backup_environment_local
 else
   hydra_backup_environment_remote $1 restore
 fi
index ae8f87ad84ea3e2b4c01c2d0916a2c76dade9d61..8f102259ae075324f92e64691d13415e0dc8618a 100755 (executable)
@@ -21,9 +21,9 @@ fi
 
 # Check restore strategy.
 if [ "$1" == "backups" ]; then
-  hydra_backup_environment_local_website $2 restore
+  hydra_backup_environment_local_website $2 $3
 elif [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
-  hydra_backup_environment_local $2 restore
+  hydra_backup_environment_local
 else
   hydra_backup_environment_remote $1 restore
 fi
index 2f15563b922b8540222a0b70ffb7f19c04d12db7..ad17fdf4d109aa9bec7c6ce44f58000f756bd1ef 100755 (executable)
@@ -12,7 +12,7 @@ DATE="`date +%Y%m%d`"
 
 # Check restore strategy.
 if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
-  hydra_backup_environment_local $2 restore
+  hydra_backup_environment_local
 else
   hydra_backup_environment_remote $1 restore
 fi
index 7dd9acfb353135c82308c07b8a9ee13fb6f09b3f..4bbaef4d3a43594f57b40995f1af36c1368a589a 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 #
-# Pack a website.
+# Backup a site.
 #
 
 # Arguments
@@ -8,7 +8,7 @@ SITES="/var/sites"
 SITE="$1"
 PACK="$1.tar.bz2"
 DATE="`date +%Y%m%d`"
-DEST="$SITES/backups/site/$SITE/$DATE"
+DEST="$SITES/backups/site/$SITE/`facter hostname`/$DATE"
 
 # Syntax check
 if [ -z "$SITE" ]; then
@@ -16,6 +16,13 @@ if [ -z "$SITE" ]; then
   exit 1
 fi
 
+# Determine site location.
+if [ "$SITE" == "git" ] && [ "$SITE" == "svn" ]; then
+  LOCATION="/var"
+else
+  LOCATION="$SITES"
+fi
+
 # Set backups user.
 if hydra_check_user backups; then
   $BACKUPS_USER="backups"
@@ -54,7 +61,7 @@ fi
 # Backup site
 if [ -d "$SITES/$SITE" ]; then
   echo "Backing up site folder..."
-  tar jcvf $PACK $SITES/$SITE
+  tar jcvf $PACK $LOCATION/$SITE
   md5sum $PACK  > $PACK.md5
   sha1sum $PACK > $PACK.sha1
   chown root.$BACKUPS_GROUP $PACK*
diff --git a/share/hydractl/backup-sites b/share/hydractl/backup-sites
new file mode 100755 (executable)
index 0000000..883566e
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+#
+# Pack multiple websites.
+#
+
+if [ -z "$1" ]; then
+  sites="`ls /var/sites`"
+else
+  sites="$*"
+fi
+
+for site in $sites; do
+  hydractl backup-site $site
+done