]> gitweb.fluxo.info Git - hydra.git/commitdiff
Unifying service restoration with hydra_backup_environment_service
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 28 Jun 2012 15:54:31 +0000 (12:54 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 28 Jun 2012 15:54:31 +0000 (12:54 -0300)
lib/hydra/backup
share/hydractl/backup-restore-email
share/hydractl/backup-restore-firma
share/hydractl/backup-restore-gitosis
share/hydractl/backup-restore-mlmmj
share/hydractl/backup-restore-schleuder
share/hydractl/backup-restore-svn
share/hydractl/backup-restore-sympa

index 02095708ba51810bc439b4f0fb841ffdfff7ff66..9ac683314ec42cc0b4b9a77dc09a906263448dba 100644 (file)
@@ -88,6 +88,39 @@ function hydra_backup_environment_remote {
   mkdir -p $RESTOREDIR
 }
 
+# Setup environment for the backups for a service
+function hydra_backup_environment_service {
+  # Check restore strategy.
+  if [ "$HOST" == "localhost" ] || [ "$HOST" == "`facter hostname`" ]; then
+    hydra_backup_environment_local
+  else
+    hydra_backup_environment_remote $HOST restore
+  fi
+  
+  # Check if folder exist on the backup.
+  if [ ! -d "$RESTOREDIR/$SERVICE_DIR" ]; then
+    echo "Service folder does not exist: $RESTOREDIR/$SERVICE_DIR"
+    exit 1
+  fi
+  
+  # Set user.
+  if hydra_check_user $SERVICE_USER; then
+    SERVICE_USER="$SERVICE_USER"
+  else
+    SERVICE_USER="root"
+  fi
+  
+  # Set group.
+  if hydra_check_group $SERVICE_GROUP; then
+    SERVICE_GROUP="$SERVICE_GROUP"
+  else
+    SERVICE_GROUP="root"
+  fi
+  
+  # TODO: Backup it?
+  #hydractl backup-$SERVICE
+}
+
 # Restore a database
 function hydra_backup_restore_database {
   DATABASE="$1"
index f0d79798d61a5c48006736f61e226b075bfa6e6d..d8d0d0c3b4d1c08e734dbc18c88edca8957e768a 100755 (executable)
@@ -22,51 +22,28 @@ hydra_config_load
 
 # Parameters.
 DATE="`date +%Y%m%d`"
-EMAIL_DIR="/var/mail/virtual"
+HOST="$1"
+SERVICE="email"
+SERVICE_DIR="/var/mail/virtual"
+SERVICE_USER="vmail"
+SERVICE_GROUP="vmail"
 
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
-  hydra_backup_environment_local
-else
-  hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/$EMAIL_DIR" ]; then
-  echo "Email folder does not exist: $RESTOREDIR/$EMAIL_DIR"
-  exit 1
-fi
-
-# Set git user.
-if hydra_check_user vmail; then
-  EMAIL_USER="vmail"
-else
-  EMAIL_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group vmail; then
-  EMAIL_GROUP="vmail"
-else
-  EMAIL_GROUP="root"
-fi
-
-# TODO: Backup it?
-#hydractl backup-email
+# Set restore environment.
+hydra_backup_environment_service
 
 # Restore email folder from backup.
 #
 # Symlink creation on site instances like drupal should be done
 # already by backup-restore-site.
-for folder in `ls $RESTOREDIR/$EMAIL_DIR`; do
-  if [ -d "$EMAIL_DIR/$folder" ]; then
-    echo "Email for user $email already exists on $EMAIL_DIR/$folder!"
+for folder in `ls $RESTOREDIR/$SERVICE_DIR`; do
+  if [ -d "$SERVICE_DIR/$folder" ]; then
+    echo "Email for user $email already exists on $SERVICE_DIR/$folder!"
   else
-    echo "Processing $EMAIL_DIR/$folder..."
-    cp -a $RESTOREDIR/$EMAIL_DIR/$folder $EMAIL_DIR/$folder
+    echo "Processing $SERVICE_DIR/$folder..."
+    cp -a $RESTOREDIR/$SERVICE_DIR/$folder $SERVICE_DIR/$folder
   fi
 done
 
 # Fix permissions.
-chown -R $EMAIL_USER.$EMAIL_GROUP $EMAIL_DIR
+chown -R $SERVICE_USER.$SERVICE_GROUP $SERVICE_DIR
 
index eaed41397cc4d964f3bf96a0656f068f090b9d74..a6e62e0085757a3dc2bc5bb2d142e0fdf743dd61 100755 (executable)
@@ -22,41 +22,18 @@ hydra_config_load
 
 # Parameters.
 DATE="`date +%Y%m%d`"
-LISTS_DIR="/var/lib/firma/lists"
+HOST="$1"
+SERVICE="firma"
+SERVICE_DIR="/var/lib/firma/lists"
+SERVICE_USER="firma"
+SERVICE_GROUP="firma"
 
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
-  hydra_backup_environment_local
-else
-  hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/$LISTS_DIR" ]; then
-  echo "Lists folder does not exist: $RESTOREDIR/$LISTS_DIR"
-  exit 1
-fi
-
-# Set git user.
-if hydra_check_user firma; then
-  LISTS_USER="firma"
-else
-  LISTS_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group firma; then
-  LISTS_GROUP="firma"
-else
-  LISTS_GROUP="root"
-fi
-
-# TODO: Backup it?
-#hydractl backup-firma
+# Set restore environment.
+hydra_backup_environment_service
 
 # Restore lists folders from backup.
-rsync -av --delete $RESTOREDIR/$LISTS_DIR/ $LISTS_DIR/
+rsync -av --delete $RESTOREDIR/$SERVICE_DIR/ $SERVICE_DIR/
 
 # Fix permissions.
-chown -R $LISTS_USER.$LISTS_GROUP $LISTS_DIR
+chown -R $SERVICE_USER.$SERVICE_GROUP $SERVICE_DIR
 
index a10b95f3bb40ff30518ecaab98f2cef6df12354a..928f3576a385bc46517f866c664d445e00040e89 100755 (executable)
@@ -21,40 +21,21 @@ source $APP_BASE/lib/hydra/functions || exit 1
 hydra_config_load
 
 # Parameters.
-DATE="`date +%Y%m%d`"
+HOST="$1"
+SERVICE="git"
+SERVICE_DIR="/var/git"
+SERVICE_USER="gitosis"
+SERVICE_GROUP="gitosis"
 
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
-  hydra_backup_environment_local
-else
-  hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/var/git" ]; then
-  echo "Git folder does not exist: $RESTOREDIR/var/git"
-  exit 1
-fi
-
-# Set git user.
-if hydra_check_user gitosis; then
-  GIT_USER="gitosis"
-else
-  GIT_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group gitosis; then
-  GIT_GROUP="gitosis"
-else
-  GIT_GROUP="root"
-fi
+# Set restore environment.
+hydra_backup_environment_service
 
 # Backup it.
+# TODO: directly at hydra_backup_environment_service
 hydractl backup-site git
 
 # Copy site folder from backup.
-cp -a $RESTOREDIR/var/git /var/git
+cp -a $RESTOREDIR/$SERVICE_DIR $SERVICE_DIR
 
 # Fix permissions.
-chown -R $GIT_USER.$GIT_GROUP /var/git
+chown -R $GIT_USER.$GIT_GROUP $SERVICE_DIR
index 6895a1181215a87fb1eabb61aefadd4563edb8d1..b175c32a7bb519020d8dbc72e9a0ab84212d9f37 100755 (executable)
@@ -22,41 +22,18 @@ hydra_config_load
 
 # Parameters.
 DATE="`date +%Y%m%d`"
-LISTS_DIR="/var/spool/mlmmj"
+HOST="$1"
+SERVICE="mlmmj"
+SERVICE_DIR="/var/spool/mlmmj"
+SERVICE_USER="mlmmj"
+SERVICE_GROUP="mlmmj"
 
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
-  hydra_backup_environment_local
-else
-  hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/$LISTS_DIR" ]; then
-  echo "Lists folder does not exist: $RESTOREDIR/$LISTS_DIR"
-  exit 1
-fi
-
-# Set git user.
-if hydra_check_user mlmmj; then
-  LISTS_USER="mlmmj"
-else
-  LISTS_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group mlmmj; then
-  LISTS_GROUP="mlmmj"
-else
-  LISTS_GROUP="root"
-fi
-
-# TODO: Backup it?
-#hydractl backup-mlmmj
+# Set restore environment.
+hydra_backup_environment_service
 
 # Restore lists folders from backup.
-rsync -av --delete $RESTOREDIR/$LISTS_DIR/ $LISTS_DIR/
+rsync -av --delete $RESTOREDIR/$SERVICE_DIR/ $SERVICE_DIR/
 
 # Fix permissions.
-chown -R $LISTS_USER.$LISTS_GROUP $LISTS_DIR
+chown -R $SERVICE_USER.$SERVICE_GROUP $SERVICE_DIR
 
index eb744d523805c66b5fba09ca86b50fa4afd8f71a..c5885f86add33e44b99588e403d13a09fc5a18b2 100755 (executable)
@@ -22,43 +22,20 @@ hydra_config_load
 
 # Parameters.
 DATE="`date +%Y%m%d`"
-LISTS_DIR="/var/lib/schleuder"
+HOST="$1"
 CONF_DIR="/etc/schleuder"
+SERVICE="schleuder"
+SERVICE_DIR="/var/lib/schleuder"
+SERVICE_USER="schleuder"
+SERVICE_GROUP="schleuder"
 
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
-  hydra_backup_environment_local
-else
-  hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/$LISTS_DIR" ]; then
-  echo "Lists folder does not exist: $RESTOREDIR/$LISTS_DIR"
-  exit 1
-fi
-
-# Set git user.
-if hydra_check_user schleuder; then
-  LISTS_USER="schleuder"
-else
-  LISTS_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group schleuder; then
-  LISTS_GROUP="schleuder"
-else
-  LISTS_GROUP="root"
-fi
-
-# TODO: Backup it?
-#hydractl backup-schleuder
+# Set restore environment.
+hydra_backup_environment_service
 
 # Restore lists folders from backup.
-rsync -av --delete $RESTOREDIR/$LISTS_DIR/ $LISTS_DIR/
+rsync -av --delete $RESTOREDIR/$SERVICE_DIR/ $SERVICE_DIR/
 rsync -av --delete $RESTOREDIR/$CONF_DIR/ $CONF_DIR/
 
 # Fix permissions.
-chown -R $LISTS_USER.$LISTS_GROUP $LISTS_DIR
+chown -R $SERVICE_USER.$SERVICE_GROUP $SERVICE_DIR
 
index 1425fdf227bb82eb64553027209f2c62d54620ad..a4c90a5e6c657e8ed484efbeeeaae4c40606eccb 100755 (executable)
@@ -22,40 +22,23 @@ hydra_config_load
 
 # Parameters.
 DATE="`date +%Y%m%d`"
+HOST="$1"
+SERVICE="svn"
+SERVICE_DIR="/var/svn"
+SERVICE_USER="svn"
+SERVICE_GROUP="svn"
 
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
-  hydra_backup_environment_local
-else
-  hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ -d "$RESTOREDIR/var/svn" ]; then
-  echo "SVN folder does not exist: $RESTOREDIR/var/svn"
-  exit 1
-fi
+# Set restore environment.
+hydra_backup_environment_service
 
 # Backup it.
+# TODO: directly at hydra_backup_environment_service
 hydractl backup-site svn
 
-# Set svn user.
-if hydra_check_user svn; then
-  SVN_USER="svn"
-else
-  SVN_USER="root"
-fi
-
-# Set svn group.
-if hydra_check_group svn; then
-  SVN_GROUP="svn"
-else
-  SVN_GROUP="root"
-fi
-
 # Copy site folder from backup.
 cp -a $RESTOREDIR/var/svn /var/svn
 
 # Fix permissions.
 chown root.root /var/svn
-chown -R $SVN_USER.$SVN_GROUP /var/svn/*
+chown -R $SERVICE_USER.$SERVICE_GROUP /var/svn/*
+
index ff1db6dee4a175e4026ebcc70ad8c45497a2828d..3bcdff4584ee58cb5353830ad5478c208a167eef 100755 (executable)
@@ -22,47 +22,24 @@ hydra_config_load
 
 # Parameters.
 DATE="`date +%Y%m%d`"
-LISTS_DIR="/var/mail/virtual"
+HOST="$1"
+SERVICE="sympa"
+SERVICE_DIR="/var/lib/sympa"
+SERVICE_USER="sympa"
+SERVICE_GROUP="sympa"
 
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
-  hydra_backup_environment_local
-else
-  hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/$LISTS_DIR" ]; then
-  echo "Lists folder does not exist: $RESTOREDIR/$LISTS_DIR"
-  exit 1
-fi
-
-# Set git user.
-if hydra_check_user sympa; then
-  LISTS_USER="sympa"
-else
-  LISTS_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group sympa; then
-  LISTS_GROUP="sympa"
-else
-  LISTS_GROUP="root"
-fi
-
-# TODO: Backup it?
-#hydractl backup-sympa
+# Set restore environment.
+hydra_backup_environment_service
 
 # Restore lists folders from backup.
-#rsync -av $RESTOREDIR/$LISTS_DIR/wwsarchive/ $LISTS_DIR/wwsarchive/
-#rsync -av $RESTOREDIR/$LISTS_DIR/expl/ $LISTS_DIR/expl/
-#rsync -av $RESTOREDIR/$LISTS_DIR/bounce/ $LISTS_DIR/bounce/
-rsync -av --delete $RESTOREDIR/$LISTS_DIR/ $LISTS_DIR/
+#rsync -av $RESTOREDIR/$SERVICE_DIR/wwsarchive/ $SERVICE_DIR/wwsarchive/
+#rsync -av $RESTOREDIR/$SERVICE_DIR/expl/ $SERVICE_DIR/expl/
+#rsync -av $RESTOREDIR/$SERVICE_DIR/bounce/ $SERVICE_DIR/bounce/
+rsync -av --delete $RESTOREDIR/$SERVICE_DIR/ $SERVICE_DIR/
 
 # Restore database
 hydra_backup_restore_database sympa
 
 # Fix permissions.
-chown -R $LISTS_USER.$LISTS_GROUP $LISTS_DIR
+chown -R $SERVICE_USER.$SERVICE_GROUP $SERVICE_DIR