summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/LinHES-system/bin/mythrestore
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2008-11-07 15:14:01 (GMT)
committerJames Meyer <james.meyer@operamail.com>2008-11-07 15:14:01 (GMT)
commit4287d6026a61f8760633574c059f6e2dead2619d (patch)
tree58b2f78c08d5edcbf7e9cdf2b8a3862e73e8afd7 /abs/core-testing/LinHES-system/bin/mythrestore
parent724988f9137cdcaf078d5e88e7efec9e664b638e (diff)
downloadlinhes_pkgbuild-4287d6026a61f8760633574c059f6e2dead2619d.zip
linhes_pkgbuild-4287d6026a61f8760633574c059f6e2dead2619d.tar.gz
linhes_pkgbuild-4287d6026a61f8760633574c059f6e2dead2619d.tar.bz2
add the r5.5 backup/restore programs.
Diffstat (limited to 'abs/core-testing/LinHES-system/bin/mythrestore')
-rwxr-xr-xabs/core-testing/LinHES-system/bin/mythrestore92
1 files changed, 92 insertions, 0 deletions
diff --git a/abs/core-testing/LinHES-system/bin/mythrestore b/abs/core-testing/LinHES-system/bin/mythrestore
new file mode 100755
index 0000000..c13d357
--- /dev/null
+++ b/abs/core-testing/LinHES-system/bin/mythrestore
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+# Let's prevent mythshutdown from shutting down the system.
+/usr/bin/mythshutdown --lock
+
+#----------------------------------------------------------------------------
+. $LinHES_ROOT/bin/backupcommon || {
+ echo 1>&2 "Can not load common settings!"
+ exit 1
+}
+#----------------------------------------------------------------------------
+
+do_file_updates() { # A function because we need to do this in two places
+ echo "Doing any needed file updates..."
+ [ -n "$UPDATE_FILES" -a -f "$UPDATE_FILES" -a -x "$UPDATE_FILES" ] &&
+ "$UPDATE_FILES"
+}
+
+do_db_updates() {
+ # We need to redo this since we just restored the old settings...
+ /usr/bin/mythshutdown --lock
+ # This is gross, but makes sure that the lock count has a sane value...
+ mysql_cmd "update settings set data = '1' where value = 'MythShutdownLock'"
+
+ # Clean up ambiguous schema version settings...
+ for val in $(mysql_cmd "select distinct value from settings where value like '%SchemaVer'") ; do
+ # Find the numeric maximum version for this schema
+ max_ver=$(mysql_cmd "select max(0 + ifnull(data, 0)) from settings where value = '$val'")
+ # Wipe out all the existing ones
+ mysql_cmd "delete from settings where value = '$val'"
+ # Insert a nice clean unique one.
+ mysql_cmd "insert into settings set value = '$val', data = '$max_ver'"
+ done
+
+ # This table causes problems with mythweb on upgrades...
+ mysql_cmd "update settings set data = '0' where value = 'WebDBSchemaVer'"
+ mysql_cmd "drop table mythweb_sessions" >/dev/null 2>&1
+}
+
+# Play a sound to let you know I'm starting.
+play_sound restore.wav
+
+# Doing this while the backend is active could be BAD.
+/etc/init.d/mythtv-backend stop
+
+# If the standard backup file exists we try to restore the files based
+# on our restore list.
+if compression=$(compression_type "$BACKUP_TAR") ; then
+ echo "Starting the restore of files..."
+ cd /
+ expand -c $BACKUP_TAR$compression |
+ /bin/tar xpvf - $RESTORE_LIST $EXCLUSION 2>&1 |
+ /bin/sed -e '/Error exit delayed from previous errors/d'
+ echo "Completed the restore of files."
+fi
+
+# If the db backup file exists start the DB restore and upgrade
+if compression=$(compression_type "$BACKUP_SQL") ; then
+ echo "Starting the DB restore, this can take a while..."
+ echo "Clearing out the existing skeleton..."
+ mysql_stdin < $DROP_SQL
+ echo "Recreating the db..."
+ /usr/bin/mysqladmin -u root create $DATABASE
+ echo "Restoring the data (long)..."
+ expand -c $BACKUP_SQL$compression | mysql_stdin
+ echo "Doing any needed db updates..."
+ [ -n "$UPDATE_SQL" -a -f "$UPDATE_SQL" ] &&
+ mysql_stdin < $UPDATE_SQL
+ echo "Completed the DB restore."
+fi
+
+echo "Sanity checking your restore..."
+play_sound vr.wav
+# Play a sound to let you know the outcome.
+if check_files_and_tables $RESTORE_LIST ; then
+ echo "Restore passes all checks."
+ play_sound restored.wav
+ STATUS=0
+else
+ echo "The restore failed or was already modified!"
+ play_sound rf.wav
+ STATUS=1
+fi
+
+# Make any updates _after_ we verify the backup...
+do_db_updates
+do_file_updates
+
+# Now it's more or less safe to restart the backend.
+/etc/init.d/mythtv-backend stop ; /etc/init.d/mythtv-backend start
+
+exit $STATUS