summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/lh_system_restore_job
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2013-01-07 18:01:37 (GMT)
committerJames Meyer <james.meyer@operamail.com>2013-01-07 18:03:24 (GMT)
commit33671693297f177c4b30c30584ddb79359a3d0ed (patch)
tree79a66f1c9080f3149be39e6c82e0df8021e61fc9 /abs/core/LinHES-system/lh_system_restore_job
parentc2e98d262d9e6003dfe7aadee5713028fb4d27cb (diff)
downloadlinhes_pkgbuild-33671693297f177c4b30c30584ddb79359a3d0ed.zip
linhes_pkgbuild-33671693297f177c4b30c30584ddb79359a3d0ed.tar.gz
linhes_pkgbuild-33671693297f177c4b30c30584ddb79359a3d0ed.tar.bz2
LinHES-system: system restore/backup modifications.
- restore: Added support for partial restores. usuage: lh_system_restore $restore_file_name partial if partial is not in the cmd line, then a full restore will take place. Partial restore of a backup file: *stop mythbackend *save a copy of the current settings for the host. This only includes the settings table and storage group definitions. * save teh entire DB (just in case) *restore the full database from the backup file *restore the copy of the settings, taken from step 1. (This is needed to keep the current configured states consistent) *start mythbackend - backup, print the name of the resulting file refs #893
Diffstat (limited to 'abs/core/LinHES-system/lh_system_restore_job')
-rw-r--r--abs/core/LinHES-system/lh_system_restore_job176
1 files changed, 141 insertions, 35 deletions
diff --git a/abs/core/LinHES-system/lh_system_restore_job b/abs/core/LinHES-system/lh_system_restore_job
index 6446e6d..eb3bd51 100644
--- a/abs/core/LinHES-system/lh_system_restore_job
+++ b/abs/core/LinHES-system/lh_system_restore_job
@@ -2,6 +2,8 @@
# This script is used to perform a quick restore of a database that was backed up via the nightly system backup
# The restore only does the database it does NOT restore system files (even if they are in the backup file)
#
+# - supplemental web, process.py
+
BACKUPDIR=/data/storage/disk0/backup/system_backups
backupfile=$1
@@ -12,19 +14,135 @@ function usage(){
echo "Files are expected to be in the $BACKUPDIR"
echo "usage:"
echo ""
- echo "lh_system_restore_job \$filename [yes]"
+ echo "lh_system_restore_job \$filename [cleanup partial]"
echo ""
echo "example: lh_system_restore_job backup.2011-12-22_15-34.tgz "
echo ""
echo ""
- echo "If the script is passed a second argument, it will not cleanup the the restore dir."
+ echo "If the script is called with cleanup, it will cleanup the the restore dir."
+ echo "If the script is called with restore, it will restore the dir, and then copy back some settings."
+ echo " It's intended to be used with restoring R7 databases only"
echo "------------------------------------------------------"
exit 1
}
+function run_cleanup(){
+ echo "Cleaning up the restore dir"
+ rm -rf $RESTOREDIR/$DIR
+ rm -f $RESTOREDIR/$backupfile
+}
+
+function restore_db(){
+
+ DIR=`echo $backupfile |cut -d. -f2`
+ CSQL="create database mythconverg;"
+ DSQL="drop database mythconverg; "
+ MYSQL="mysql -u mythtv -pmythtv"
+
+
+
+ mkdir -p $RESTOREDIR
+ cp $BACKUPDIR/$backupfile $RESTOREDIR
+ cd $RESTOREDIR && tar -xf $backupfile && cd $DIR
+
+ if [ -f mythconverg ]
+ then
+ #drop the db
+ $MYSQL -e "$DSQL"
+ #create the db
+ $MYSQL -e "$CSQL"
+ #restore the database_backup
+ echo "Restoring database $DIR"
+ $MYSQL mythconverg < mythconverg
+ if [ $? = 0 ]
+ then
+ echo "Done"
+ else
+ echo "An error occured"
+ fi
+ else
+ echo "Couldn't file a file to restore"
+ fi
+
+ }
+
+
+
+function run_prestore(){
+ echo "Partial restore of database"
+ echo "---------------------------------"
+ echo
+ #save settings to group
+ echo " Saving current database settings for selective import"
+ #mythutil --save-settings --groupname pre_db_restore > /tmp/prestore.out
+ #mythutil --export-settings --generic --outfile $RESTOREDIR/pre_db.export --tablelist settings 2>&1 >> /tmp/prestore.out
+ #sed -i "s/settings/settings_pre_db/g" $RESTOREDIR/pre_db.export
+
+ mythutil --export-settings --outfile $RESTOREDIR/pre_db.exports.xml --tablelist settings --generic 2> /dev/null >> /tmp/prestore.out
+
+
+ #save storage groups
+ #mythutil --export-settings --generic --outfile /tmp/pre_db_sg.export --tablelist storagegroup
+ mysqldump mythconverg storagegroup > $RESTOREDIR/sg.sql
+
+ #stop mythbackend
+ echo " Stopping mythbackend"
+ lh_backend_control.sh stop
+
+ #do backup
+ echo " Backing up current database"
+ lh_system_backup_job 2>/dev/null >> /tmp/prestore.out
+
+ # restore mythconverg
+ restore_db
+ mysqldump mythconverg storagegroup > $RESTOREDIR/backupfile_sg.sql
+ mysql mythconverg -e "truncate storagegroup;"
+ # restore exported settings
+ echo " Importing previous settings into settings_pre_db"
+ mythutil --import-settings --infile $RESTOREDIR/pre_db.exports.xml --hostname `hostname` 2>/dev/null >> /tmp/prestore.out
+ #mythutil --import-settings --infile $RESTOREDIR/pre_db.export 2>&1 >> /tmp/prestore.out
+ # restore storage_groups
+ mysql mythconverg < $RESTOREDIR/sg.sql
+
+ #start mythbackend
+ echo " Starting mythbackend"
+ lh_backend_control.sh start
+ echo
+ echo "Partial restore complete."
+ echo "All data for `hostname` has been restored except:"
+ echo "* storage groups definitions"
+ echo "* service menu settings"
+
+
+}
+
+function run_full_restore(){
+ echo "Full restore of database"
+ echo "---------------------------------"
+ echo
+ #stop mythbackend
+ echo " Stopping mythbackend"
+ lh_backend_control.sh stop
+ echo
+ #do backup
+ echo " Backing up current database"
+ lh_system_backup_job 2>/dev/null >> /tmp/prestore.out
+ echo
+ # restore mythconverg
+ restore_db
+ echo
+ #start mythbackend
+ echo " Starting mythbackend"
+ lh_backend_control.sh start
+ echo
+ echo "Restore complete"
+}
+
+
+#-----------------------Main program --------------------------
if [ x$backupfile = x ]
then
@@ -33,44 +151,32 @@ fi
MYTH_RUN_STATUS="1"
. /etc/profile
-RESTOREDIR=$BACKUPDIR/restore
-DIR=`echo $backupfile |cut -d. -f2`
-CSQL="create database mythconverg;"
-DSQL="drop database mythconverg; "
-MYSQL="mysql -u mythtv -pmythtv"
-
-
+prestore="false"
+cleanup="false"
+for i in $*; do
+ #echo $i
+ if [ $i = "cleanup" ]
+ then
+ cleanup="true"
+ fi
+ if [ $i = "partial" ]
+ then
+ prestore="true"
+ fi
+done
+RESTOREDIR=$BACKUPDIR/restore
mkdir -p $RESTOREDIR
-cp $BACKUPDIR/$backupfile $RESTOREDIR
-cd $RESTOREDIR && tar -xf $backupfile && cd $DIR
-if [ -f mythconverg ]
+if [ $prestore = "true" ]
then
- #drop the db
- $MYSQL -e "$DSQL"
- #create the db
- $MYSQL -e "$CSQL"
- #restore the database_backup
- echo "Restoring the database $DIR"
- $MYSQL mythconverg < mythconverg
- if [ $? = 0 ]
- then
- echo "Done"
- else
- echo "An error occured"
- fi
- else
- echo "Couldn't file a file to restore"
+ run_prestore
+else
+ run_full_restore
fi
-
-#cleanup
-if [ x$2 = x ]
+if [ $cleanup = "true" ]
then
- echo "Cleaning up the restore dir"
- rm -rf $RESTOREDIR/$DIR
- rm -f $RESTOREDIR/$backupfile
-else
- echo "Not doing a cleanup of $RESTOREDIR"
+ run_cleanup
fi
+