summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/lh_system_restore_job
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2013-02-01 02:01:24 (GMT)
committerJames Meyer <james.meyer@operamail.com>2013-02-01 02:01:24 (GMT)
commitbf9991d8258086515c1350d8719622c659924f37 (patch)
treefac9a7bfaffa435f69ecf7778509a1a78b9d802c /abs/core/LinHES-system/lh_system_restore_job
parentc7b9f42f1d529a30bb3534330e4973272d225593 (diff)
downloadlinhes_pkgbuild-bf9991d8258086515c1350d8719622c659924f37.zip
linhes_pkgbuild-bf9991d8258086515c1350d8719622c659924f37.tar.gz
linhes_pkgbuild-bf9991d8258086515c1350d8719622c659924f37.tar.bz2
LinHES-system: add lh_system_restore and lh_system_backup. These scripts are called from the mythmenu.
refs #900
Diffstat (limited to 'abs/core/LinHES-system/lh_system_restore_job')
-rw-r--r--abs/core/LinHES-system/lh_system_restore_job134
1 files changed, 97 insertions, 37 deletions
diff --git a/abs/core/LinHES-system/lh_system_restore_job b/abs/core/LinHES-system/lh_system_restore_job
index eb3bd51..da7dbca 100644
--- a/abs/core/LinHES-system/lh_system_restore_job
+++ b/abs/core/LinHES-system/lh_system_restore_job
@@ -2,10 +2,16 @@
# 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
+# - supplemental web, process.py , lh_system_restore
+. /etc/systemconfig
BACKUPDIR=/data/storage/disk0/backup/system_backups
+RESTOREDIR=$BACKUPDIR/restore
backupfile=$1
+restore_status=0
+
+MYTH_RUN_STATUS="1"
+. /etc/profile
function usage(){
echo "------------------------------------------------------"
@@ -26,7 +32,15 @@ function usage(){
echo "------------------------------------------------------"
exit 1
- }
+}
+
+function restore_status_check(){
+ if [ $1 -ne 0 ]
+ then
+ restore_status=1
+ fi
+}
+
function run_cleanup(){
echo "Cleaning up the restore dir"
@@ -34,18 +48,18 @@ function run_cleanup(){
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"
-
-
-
+function expand_restore_file(){
mkdir -p $RESTOREDIR
+ DIR=`echo $backupfile |cut -d. -f2`
cp $BACKUPDIR/$backupfile $RESTOREDIR
cd $RESTOREDIR && tar -xf $backupfile && cd $DIR
+ restore_status_check $?
+}
+
+function restore_db(){
+ CSQL="create database mythconverg;"
+ DSQL="drop database mythconverg; "
+ MYSQL="mysql -u mythtv -pmythtv"
if [ -f mythconverg ]
then
@@ -56,18 +70,52 @@ function restore_db(){
#restore the database_backup
echo "Restoring database $DIR"
$MYSQL mythconverg < mythconverg
- if [ $? = 0 ]
+ rc=$?
+ restore_status_check $rc
+
+ if [ $rc = 0 ]
then
- echo "Done"
+ echo "Restore of mythconverg complete"
else
- echo "An error occured"
+ echo "An error occurred restoring mythconverg"
fi
+
else
- echo "Couldn't file a file to restore"
+ echo "Couldn't find file mythconverg to restore"
+ restore_status=1
fi
- }
+}
+function restore_ncid(){
+ CSQL="create database ncid;"
+ DSQL="drop database ncid; "
+ MYSQL="mysql -u root "
+
+ if [ -f ncid ]
+ then
+ #drop the db
+ $MYSQL -e "$DSQL"
+ #create the db
+ $MYSQL -e "$CSQL"
+ #restore the database_backup
+ echo "Restoring database $DIR"
+ $MYSQL ncid < ncid
+ rc=$?
+ #restore_status_check $rc
+
+ if [ $rc = 0 ]
+ then
+ echo "Restore of ncid complete"
+ else
+ echo "An error occurred restoring ncid"
+ fi
+
+ else
+ echo "Couldn't find file ncid to restore"
+ fi
+
+}
function run_prestore(){
@@ -76,40 +124,32 @@ function run_prestore(){
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_ncid
# 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:"
@@ -120,36 +160,54 @@ function run_prestore(){
}
function run_full_restore(){
- echo "Full restore of database"
+ echo "Full restore"
echo "---------------------------------"
echo
+ cp -f etc/systemconfig /etc/systemconfig
+
+ if [ $SystemType = Master_backend -o $SystemType = Standalone ]
+ then
#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
+ restore_ncid
+ echo
+
#start mythbackend
echo " Starting mythbackend"
lh_backend_control.sh start
echo
+
+ else
+ # didn't restore the database, so restore FE settings
+ if [ -e settings ]
+ then
+ rsync -arvp settings/* /usr/MythVantage/templates/settings/
+ fi
+
+ if [ -e /usr/MythVantage/templates/settings/syssettings ]
+ then
+ myth_settings_wrapper.sh -c restore -t syssettings
+ restore_status_check $?
+ else
+ echo "Couldn't find syssettings file"
+ fi
+ fi
+ systemconfig.py -m all
echo "Restore complete"
}
-
#-----------------------Main program --------------------------
if [ x$backupfile = x ]
then
usage
fi
-MYTH_RUN_STATUS="1"
-. /etc/profile
prestore="false"
cleanup="false"
@@ -160,13 +218,14 @@ for i in $*; do
then
cleanup="true"
fi
+
if [ $i = "partial" ]
then
prestore="true"
fi
done
-RESTOREDIR=$BACKUPDIR/restore
-mkdir -p $RESTOREDIR
+
+expand_restore_file
if [ $prestore = "true" ]
then
@@ -180,3 +239,4 @@ then
run_cleanup
fi
+exit $restore_status