summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/lh_system_backup_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_backup_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_backup_job')
-rw-r--r--abs/core/LinHES-system/lh_system_backup_job104
1 files changed, 89 insertions, 15 deletions
diff --git a/abs/core/LinHES-system/lh_system_backup_job b/abs/core/LinHES-system/lh_system_backup_job
index 3a13ade..e095a97 100644
--- a/abs/core/LinHES-system/lh_system_backup_job
+++ b/abs/core/LinHES-system/lh_system_backup_job
@@ -1,25 +1,69 @@
#!/bin/bash
#process that uses this system backup script
# - myth_mtc.py
-# - supplemental web, process.py backup
+# - supplemental web, process.py backup linhes_backup_wrapper
+
MYTH_RUN_STATUS="1"
. /etc/profile
. /etc/systemconfig
BACKUPDIR=/data/storage/disk0/backup/system_backups
DELETE_DAYS=21
DATE=`date +%F_%H-%M`
+backup_status=0
#
+
+MYTHSHUTDOWN="/usr/bin/mythshutdown"
+
+function lock_myth(){
+ $MYTHSHUTDOWN --lock
+}
+
+function unlock_myth(){
+ $MYTHSHUTDOWN --unlock
+}
+
+function backup_status_check(){
+ if [ $1 -ne 0 ]
+ then
+ backup_status=1
+ fi
+}
+
+
function backup(){
+
echo "#######################################"
echo "Starting backup "
mkdir -p $BACKUPDIR/$DATE
- #backup db
- pacman -Q mysql 2>/dev/null
- if [ $? = 0 ]
+ #backup database
+ if [ $SystemType = Master_backend -o $SystemType = Standalone ]
+ then
+ pacman -Q mysql 2>/dev/null
+ if [ $? = 0 ]
+ then
+ mysqldump -x mythconverg > $BACKUPDIR/$DATE/mythconverg
+ backup_status_check $?
+
+ mysqldump -x ncid > $BACKUPDIR/$DATE/ncid
+
+ #this is all the users
+ mysqldump -x mysql > $BACKUPDIR/$DATE/mysql_table
+
+ #this is everything
+ mysqldump -x --all-databases > $BACKUPDIR/$DATE/all_databases
+ backup_status_check $?
+
+
+
+ fi
+ fi
+
+ #backup saved settings
+ if [ -e /usr/MythVantage/templates/settings ]
then
- mysqldump mythconverg > $BACKUPDIR/$DATE/mythconverg
- mysqldump ncid > $BACKUPDIR/$DATE/ncid
+ cp -rp /usr/MythVantage/templates/settings $BACKUPDIR/$DATE/settings
+ backup_status_check $?
fi
#backup etc
@@ -27,6 +71,7 @@ function backup(){
if [ -e /var/lib/oss ]
then
cp -rp /var/lib/oss $BACKUPDIR/$DATE/oss
+ backup_status_check $?
fi
#backup func keys
@@ -47,16 +92,17 @@ function backup(){
if [ -f $MYTHHOME/backup_config/backup_include.txt ]
then
tar -zcf $BACKUPDIR/$DATE/other.tar.gz -T $MYTHHOME/backup_config/backup_include.txt
+ backup_status_check $?
fi
#make_zip file
cd $BACKUPDIR
tar -zcvf $BACKUPDIR/backup.$DATE.tgz $DATE
-
- if [ -d $BACKUPDIR/$DATE ]
- then
- rm -rf $BACKUPDIR/$DATE
- fi
+ backup_status_check $?
+ if [ -d $BACKUPDIR/$DATE ]
+ then
+ rm -rf $BACKUPDIR/$DATE
+ fi
if [ -f /home/xymon/server/ext/hbnotes.py ]
then
@@ -69,6 +115,29 @@ function backup(){
echo "########################################"
}
+function update_backup_status(){
+ # Add Last backup status to menu item
+ #if description not in the backup xml file, add it
+ if [ $rc=0 ]
+ then
+ COMPLETE_MSG="Last backup completed on `date '+%D @ %-I:%M %p'`"
+ else
+ COMPLETE_MSG="Last backup FAILED on `date '+%D @ %-I:%M %p'`"
+ fi
+
+ xmlfile="/usr/share/mythtv/themes/defaultmenu/mythbackup.xml"
+
+ grep -q "<description>" $xmlfile >/dev/null
+ desc_check=$?
+
+ if [ $desc_check = 0 ]
+ then
+ sed -i "s_\<description\>.*\<description\>_description\>$COMPLETE_MSG\<\/description_" $xmlfile
+ else
+ sed -i " /NONE/ i\ \<description\>$COMPLETE_MSG\<\/description\>" $xmlfile
+ fi
+}
+
function remove_old_backups(){
#remove old backups
find $BACKUPDIR/backup*.tgz -type f -mtime +$DELETE_DAYS -delete
@@ -109,7 +178,7 @@ function remote_transfer(){
rc=$?
if [ $rc = 0 ]
then
- #this is here to mark failed copy of the backup.
+ #this is here to mark a failed copy of the backup.
#There is a cron.hourly job that will attempt to retransfer the file
echo "Remote backup failed to ${RemoteBackupDir}"
echo $transfer_file >> $BACKUPDIR/remote_backup_failed.txt
@@ -124,7 +193,7 @@ function add_link(){
then
RETRYFILE="/etc/cron.hourly/lh_backup_retry.sh"
echo "#!/bin/bash" > $RETRYFILE
- echo "#This file was autogenerated and removed by lh_system_backup_job" >> $RETRYFILE
+ echo "#This file was autogenerated and will be removed by lh_system_backup_job" >> $RETRYFILE
echo "MYTH_RUN_STATUS=1">> $RETRYFILE
echo ". /etc/profile">> $RETRYFILE
echo "lh_system_backup_job retry">> $RETRYFILE
@@ -139,11 +208,15 @@ function remove_link(){
rm -f $RETRYFILE
fi
}
+
+
#------------------------------------
+lock_myth
if [ "x$1" = "x" ]
then
remove_old_backups
backup
+ update_backup_status
remote_backup
add_link
else
@@ -160,6 +233,7 @@ else
fi
remove_link
fi
-
-
+unlock_myth
+echo $backup_status > /var/run/systembackup.rc
+exit $backup_status