diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/hydra/backup | 34 |
1 files changed, 34 insertions, 0 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 +} |