From d5370e5d6fe083e14866c5b5d1728fea4f9879bc Mon Sep 17 00:00:00 2001 From: James Meyer Date: Tue, 3 Dec 2013 16:17:25 -0600 Subject: LinHES-system: systembackup lh_system_backup_job. Fix sed problem when adjusting the meny xml . Changed > to -gt to force bash int test instead of string add timestamps to myth_mtc.py and general cleanup --- abs/core/LinHES-system/PKGBUILD | 6 ++--- abs/core/LinHES-system/lh_system_backup_job | 38 +++++++++++++++++----------- abs/core/LinHES-system/myth_mtc.py | 39 +++++++++++++++++++++-------- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD index 5b714f6..406cc05 100755 --- a/abs/core/LinHES-system/PKGBUILD +++ b/abs/core/LinHES-system/PKGBUILD @@ -1,6 +1,6 @@ pkgname=LinHES-system pkgver=8.1 -pkgrel=5 +pkgrel=6 arch=('i686' 'x86_64') install=system.install pkgdesc="Everything that makes LinHES an automated system" @@ -79,7 +79,7 @@ md5sums=('49e9847cedcf26a977d64fd44e460b11' 'de32a1c50101265dd7f6ca5037f7a26a' 'a875ee97f86e46f34a741c2bc455f894' '76b2637cac0452b3acdbeeb4e8a5474b' - '781c977f8872543f033dad2caaf0458e' + '79a63270794ef7de244af10dad51330a' '6f5b757524d905b5d2420519a88edc93' 'dc3eef2a624754e16805d72bbe488b67' '617af86b901538817ebdcaf646248dc5' @@ -92,7 +92,7 @@ md5sums=('49e9847cedcf26a977d64fd44e460b11' '33fbebbd546672cedd3c5e7350ab414e' 'c773d8caacba8fbd4968e8afe5137bc6' '3edef50a49a47694bf8add39cc160add' - '95e586cdbf0bef7ec2d99463b47a9096' + 'aa6010065f5ec2afe1d2bee4cf81dec7' 'bc69a520add58ede9b060c73e67ace13' '26fdd26e945f0c187f9fdcf98a7a5bef' '47e093e8cfe4b5b96602358e1f540832' diff --git a/abs/core/LinHES-system/lh_system_backup_job b/abs/core/LinHES-system/lh_system_backup_job index 9b878bd..7d05be5 100644 --- a/abs/core/LinHES-system/lh_system_backup_job +++ b/abs/core/LinHES-system/lh_system_backup_job @@ -43,15 +43,19 @@ function backup(){ pacman -Q mysql 2>/dev/null if [ $? = 0 ] then + echo " mythconverg (mythtv database)" mysqldump -x mythconverg > $BACKUPDIR/$DATE/mythconverg backup_status_check $? - mysqldump -x ncid > $BACKUPDIR/$DATE/ncid + echo " ncid (caller id)" + mysqldump -x ncid > $BACKUPDIR/$DATE/ncid 2>/dev/null #this is all the users + echo " users" mysqldump -x mysql > $BACKUPDIR/$DATE/mysql_table #this is everything + echo " All databases in one file" mysqldump -x --all-databases > $BACKUPDIR/$DATE/all_databases backup_status_check $? @@ -117,6 +121,7 @@ function backup(){ } function update_backup_status(){ + echo # Add Last backup status to menu item #if description not in the backup xml file, add it if [ $rc=0 ] @@ -125,7 +130,8 @@ function update_backup_status(){ else COMPLETE_MSG="Last backup FAILED `date '+%D %-I:%M %p'`" fi - + echo "Updating menu with:" + echo " $COMPLETE_MSG" xmlfile="/usr/share/mythtv/themes/defaultmenu/mythbackup.xml" grep -q "" $xmlfile >/dev/null @@ -133,16 +139,18 @@ function update_backup_status(){ if [ $desc_check = 0 ] then - sed -i "0,/\.*\/s//\$COMPLETE_MSG\<\/description/" $xmlfile + sed -i "0,/.*\/s||\$COMPLETE_MSG<\/description|" $xmlfile + #sed -i "0,/\.*\/s//\$COMPLETE_MSG\<\/description/" $xmlfile else sed -i " /NONE/ i\ \$COMPLETE_MSG\<\/description\>" $xmlfile fi } function remove_old_backups(){ + #remove old backups NumBackups=`ls $BACKUPDIR/backup*.tgz|wc -l` - if [[ $NumBackups > $KeepBackups ]]; then + if [[ $NumBackups -gt $KeepBackups ]]; then numdel=$(($NumBackups-$KeepBackups)) rm -f `ls $BACKUPDIR/backup*.tgz -tr1|head -$numdel` fi @@ -150,6 +158,8 @@ function remove_old_backups(){ function remote_backup(){ + echo + echo "Remote backup" #Remote copy if [ x$RemoteBackup = x1 ] then @@ -157,7 +167,7 @@ function remote_backup(){ if [ x$localRemoteCheck = xdir ] then localRemotedir=`echo $RemoteBackupDir | cut -d: -f2` - echo "copying $BACKUPDIR/backup.$DATE.tgz to $localRemotedir " + echo " copying $BACKUPDIR/backup.$DATE.tgz to $localRemotedir " cp $BACKUPDIR/backup.$DATE.tgz $localRemotedir else /usr/bin/func ${RemoteBackupDir} ping| grep -q "FAILED" @@ -166,15 +176,15 @@ function remote_backup(){ then #this is here to mark 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 " Remote backup failed to ${RemoteBackupDir}" echo backup.$DATE.tgz >> $BACKUPDIR/remote_backup_failed.txt else - echo "copying $BACKUPDIR/backup.$DATE.tgz to ${RemoteBackupDir}:$BACKUPDIR/MBE_$DATE.tgz" + echo " copying $BACKUPDIR/backup.$DATE.tgz to ${RemoteBackupDir}:$BACKUPDIR/MBE_$DATE.tgz" /usr/bin/func ${RemoteBackupDir} copyfile -f $BACKUPDIR/backup.$DATE.tgz --remotepath $BACKUPDIR/MBE_$DATE.tgz fi fi else #do local copy to SECBACKUPLINK - echo "Remote backup is not enabled, copying backup to $SECBACKUPLINK if it exists" + echo " Remote backup is not enabled, copying backup to $SECBACKUPLINK if it exists" SECBACKUPDISK=`readlink $SECBACKUPLINK` SECBACKUP=$SECBACKUPDISK/backup @@ -182,16 +192,16 @@ function remote_backup(){ if [ `mountpoint -q -d $SECBACKUPDISK` ]; then if [ ! -d "$SECBACKUP" ]; then mkdir -p -m 775 $SECBACKUP - echo "Created $SECBACKUP" + echo " Created $SECBACKUP" chown mythtv:users $SECBACKUP fi - echo "Copying systems_backups" + echo " Copying system backups to $SECBACKUP" rsync -au --delete $BACKUPDIR $SECBACKUP else - echo "$SECBACKUPDISK isn't mounted." + echo "* $SECBACKUPDISK isn't mounted." fi else - echo "Link $SECBACKUPLINK doesn't exist." + echo "* Link $SECBACKUPLINK doesn't exist." fi fi } @@ -205,10 +215,10 @@ function remote_transfer(){ then #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 " Remote backup failed to ${RemoteBackupDir}" echo $transfer_file >> $BACKUPDIR/remote_backup_failed.txt else - echo "copying $BACKUPDIR/$transfer_file to ${RemoteBackupDir}:$BACKUPDIR/MBE_$transfer_file" + echo " copying $BACKUPDIR/$transfer_file to ${RemoteBackupDir}:$BACKUPDIR/MBE_$transfer_file" /usr/bin/func ${RemoteBackupDir} copyfile -f $BACKUPDIR/$transfer_file --remotepath $BACKUPDIR/MBE_$transfer_file fi } diff --git a/abs/core/LinHES-system/myth_mtc.py b/abs/core/LinHES-system/myth_mtc.py index a5f02a0..2c1fd14 100755 --- a/abs/core/LinHES-system/myth_mtc.py +++ b/abs/core/LinHES-system/myth_mtc.py @@ -14,13 +14,21 @@ except: #print mythtv.db.getSetting( 'Theme', socket.gethostname()) +def get_timestamp(): + now = datetime.datetime.now() +#date = "%s-%s-%s" %(now.year, now.month, now.day) + date = (now.strftime('%Y-%m-%d %H:%M')) + return date + + def optimize(): + try: cursor = mythtv.db.cursor() cursor.execute("SHOW tables") result = cursor.fetchall() except: - print "Problem getting tables from database" + print " Problem getting tables from database" return ops=["REPAIR","OPTIMIZE","ANALYZE"] for row in result: @@ -32,6 +40,7 @@ def optimize(): def upcoming_check(): + print " Checking for upcoming shows" try: upcoming = mythtv.getUpcomingRecordings() except: @@ -50,11 +59,12 @@ def upcoming_check(): if ( time_diff > 30) : return True else: - print show , "is upcoming in " , time_diff + print " %s is upcoming in %s" %(show,time_diff) return False def schemalock_check(): + print " Checking if schema is locked" try: c = mythtv.db.cursor() c.execute("select count(*) from schemalock") @@ -66,10 +76,11 @@ def schemalock_check(): if schemalock == 0: return True else: - print "schema is locked" + print " schema is locked" return False def job_check(): + print " Checking jobqueue" try: c = mythtv.db.cursor() c.execute("select count(*) from jobqueue where status = 4") @@ -80,11 +91,12 @@ def job_check(): if jobs == 0 : return True else: - print " jobs are running" + print " jobs are running" return False def in_use(): + print " Checking if programs are in use" try: c = mythtv.db.cursor() c.execute("select count(*) from inuseprograms") @@ -95,10 +107,11 @@ def in_use(): if prginuse == 0 : return True else: - print "programs in use" + print " Programs in use" return False def mfd_check(): + print " Checking is mythfilldatabase is running" ps = subprocess.Popen("ps ax -o pid= -o args= ", shell=True, stdout=subprocess.PIPE) ps_pid = ps.pid output = ps.stdout.read() @@ -110,7 +123,7 @@ def mfd_check(): if res: pid = int(res[0][0]) if proc_name in res[0][1] and pid != os.getpid() and pid != ps_pid: - print "mythfilldatabase is running" + print " mythfilldatabase is running" return False return True @@ -118,23 +131,24 @@ def mfd_check(): def idle_check(): + print "%s Checking idle" %(get_timestamp()) if ( upcoming_check() and schemalock_check() and job_check() and in_use() and mfd_check() ): idle=True - print "Myth is idle" + print "\n%s Myth is idle" %(get_timestamp()) else: idle=False - print "Myth is NOT idle" + print "\n%s Myth is NOT idle" %(get_timestamp()) return idle def run_stuff(): if idle_check(): - print "Running optimize" + print "\n%sRunning optimize" %(get_timestamp()) optimize() - print "Running backup" + print "\n%s Running backup" %(get_timestamp()) os.system('/usr/LH/bin/lh_system_backup_job') - print "Running system_update" + print "\n%s Running system update" %(get_timestamp()) os.system('/usr/LH/bin/lh_system_host_update') continue_loop=False else: @@ -146,8 +160,11 @@ starttime=time.time() ctin=True while ctin: ctin=run_stuff() + print "\n" if ctin: + print "%s Waiting 10 minutes before trying again" %(get_timestamp()) time.sleep(600) + current_time=time.time() if (current_time - starttime) > 10800 : ctin = False -- cgit v0.12