summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/hydra/backup34
-rwxr-xr-xshare/hydractl/backup-restore-site24
-rwxr-xr-xshare/hydractl/backup-restore-sympa27
3 files changed, 36 insertions, 49 deletions
diff --git a/lib/hydra/backup b/lib/hydra/backup
index e3edf50..0209570 100644
--- a/lib/hydra/backup
+++ b/lib/hydra/backup
@@ -87,3 +87,37 @@ function hydra_backup_environment_remote {
DB_DUMP_BASE="$RESTOREDIR/var/backups/mysql/sqldump/"
mkdir -p $RESTOREDIR
}
+
+# Restore a database
+function hydra_backup_restore_database {
+ DATABASE="$1"
+
+ if [ -z "$DATABASE" ]; then
+ return
+ fi
+
+ # Check if there are database dumps
+ if [ -f "$DB_DUMP_BASE/$DATABASE.sql.gz" ]; then
+ DB_DUMP_EXT=".gz"
+ DB_DUMP_EXTRACT="gunzip"
+ elif [ -f "$DB_DUMP_BASE/$DATABASE.sql.bz2" ]; then
+ DB_DUMP_EXT=".bz2"
+ DB_DUMP_EXTRACT="bunzip2"
+ elif [ -f "$DB_DUMP_BASE/$DATABASE.sql" ]; then
+ DB_DUMP_EXT=""
+ DB_DUMP_EXTRACT="true"
+ fi
+
+ # Restore database
+ if [ ! -z "$DB_DUMP_EXT" ]; then
+ echo "Restoring database $DATABASE..."
+ hydra_set_tmpfile $DATABASE -d
+ cp $DB_DUMP_BASE/$DATABASE.sql$DB_DUMP_EXT $TMPWORK
+ ( cd $TMPWORK && $DB_DUMP_EXTRACT $DATABASE.sql$DB_DUMP_EXT )
+ hydra_truncate_database $DATABASE
+ mysql $DATABASE < $TMPWORK/$DATABASE.sql
+ hydra_unset_tmpfile $TMPWORK
+ else
+ echo "Database should be manually restored"
+ fi
+}
diff --git a/share/hydractl/backup-restore-site b/share/hydractl/backup-restore-site
index 3c22e52..f9d7acc 100755
--- a/share/hydractl/backup-restore-site
+++ b/share/hydractl/backup-restore-site
@@ -146,30 +146,8 @@ if [ -e "$FOLDER/drupal" ]; then
fi
fi
-# Check if there are database dumps
-if [ -f "$DB_DUMP_BASE/$SITE.sql.gz" ]; then
- DB_DUMP_EXT=".gz"
- DB_DUMP_EXTRACT="gunzip"
-elif [ -f "$DB_DUMP_BASE/$SITE.sql.bz2" ]; then
- DB_DUMP_EXT=".bz2"
- DB_DUMP_EXTRACT="bunzip2"
-elif [ -f "$DB_DUMP_BASE/$SITE.sql" ]; then
- DB_DUMP_EXT=""
- DB_DUMP_EXTRACT="true"
-fi
-
# Restore database
-if [ ! -z "$DB_DUMP_EXT" ]; then
- echo "Restoring database $SITE..."
- hydra_set_tmpfile $SITE -d
- cp $DB_DUMP_BASE/$SITE.sql$DB_DUMP_EXT $TMPWORK
- ( cd $TMPWORK && $DB_DUMP_EXTRACT $SITE.sql$DB_DUMP_EXT )
- hydra_truncate_database $SITE
- mysql $SITE < $TMPWORK/$SITE.sql
- hydra_unset_tmpfile $TMPWORK
-else
- echo "Database should be manually restored"
-fi
+hydra_backup_restore_database $SITE
# Ikiwiki
if [ -e "$FOLDER/ikiwiki" ]; then
diff --git a/share/hydractl/backup-restore-sympa b/share/hydractl/backup-restore-sympa
index 5f13665..ff1db6d 100755
--- a/share/hydractl/backup-restore-sympa
+++ b/share/hydractl/backup-restore-sympa
@@ -23,7 +23,6 @@ hydra_config_load
# Parameters.
DATE="`date +%Y%m%d`"
LISTS_DIR="/var/mail/virtual"
-SITE="sympa"
# Check restore strategy.
if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
@@ -61,32 +60,8 @@ fi
#rsync -av $RESTOREDIR/$LISTS_DIR/bounce/ $LISTS_DIR/bounce/
rsync -av --delete $RESTOREDIR/$LISTS_DIR/ $LISTS_DIR/
-DB_DUMP_BASE="$RESTOREDIR/var/backups/mysql/sqldump"
-
-# Check if there are database dumps
-if [ -f "$DB_DUMP_BASE/$SITE.sql.gz" ]; then
- DB_DUMP_EXT=".gz"
- DB_DUMP_EXTRACT="gunzip"
-elif [ -f "$DB_DUMP_BASE/$SITE.sql.bz2" ]; then
- DB_DUMP_EXT=".bz2"
- DB_DUMP_EXTRACT="bunzip2"
-elif [ -f "$DB_DUMP_BASE/$SITE.sql" ]; then
- DB_DUMP_EXT=""
- DB_DUMP_EXTRACT="true"
-fi
-
# Restore database
-if [ ! -z "$DB_DUMP_EXT" ]; then
- echo "Restoring database $SITE..."
- hydra_set_tmpfile $SITE -d
- cp $DB_DUMP_BASE/$SITE.sql$DB_DUMP_EXT $TMPWORK
- ( cd $TMPWORK && $DB_DUMP_EXTRACT $SITE.sql$DB_DUMP_EXT )
- hydra_truncate_database $SITE
- mysql $SITE < $TMPWORK/$SITE.sql
- hydra_unset_tmpfile $TMPWORK
-else
- echo "Database should be manually restored"
-fi
+hydra_backup_restore_database sympa
# Fix permissions.
chown -R $LISTS_USER.$LISTS_GROUP $LISTS_DIR