summaryrefslogtreecommitdiffstats
path: root/abs/core
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
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')
-rwxr-xr-xabs/core/LinHES-system/PKGBUILD6
-rw-r--r--abs/core/LinHES-system/lh_system_backup_job4
-rw-r--r--abs/core/LinHES-system/lh_system_restore_job176
3 files changed, 148 insertions, 38 deletions
diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD
index fa3fa2b..2cb8997 100755
--- a/abs/core/LinHES-system/PKGBUILD
+++ b/abs/core/LinHES-system/PKGBUILD
@@ -1,6 +1,6 @@
pkgname=LinHES-system
pkgver=2
-pkgrel=133
+pkgrel=134
arch=('i686' 'x86_64')
MVDIR=$startdir/pkg/usr/LH
BINDIR=$startdir/pkg/usr/bin
@@ -95,8 +95,8 @@ md5sums=('d275db0a946087671e0c2014dac9ed22'
'692563448cca1d49f45e7d1c8abcaa0c'
'962a3e9eaba2d1466251b7ab0956705d'
'1758aed160de64abfafb28a3a8f3390e'
- '5ec620e9339c8c7a58a729b9763c9bfb'
- 'ceec78815ed01af733cdbca14cb0942b'
+ '1da34ffbe6dccfdf202bdd03edd6bb28'
+ '079085b1ad92e23a1c3399ad1dcf7486'
'1be1d3dfc83f828eede93055713882ae'
'47e093e8cfe4b5b96602358e1f540832'
'a85c19902f2af90931e05c839c63b62d'
diff --git a/abs/core/LinHES-system/lh_system_backup_job b/abs/core/LinHES-system/lh_system_backup_job
index 3f82216..98d4168 100644
--- a/abs/core/LinHES-system/lh_system_backup_job
+++ b/abs/core/LinHES-system/lh_system_backup_job
@@ -2,6 +2,7 @@
#process that uses this system backup script
# - myth_mtc.py
# - supplemental web, process.py backup
+
MYTH_RUN_STATUS="1"
. /etc/profile
. /etc/systemconfig
@@ -44,6 +45,9 @@ function backup(){
/home/xymon/server/ext/hbnotes.py
chown nobody:nobody /data/srv/httpd/htdocs/hobbit/notes/* 2> /dev/null >/dev/null
fi
+ echo
+ echo "Created file:"
+ echo " $BACKUPDIR/backup.$DATE.tgz"
echo "########################################"
}
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
+