From 98d505858997aa3d1839e221868949b520f93c97 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Fri, 22 Jan 2016 20:28:16 +0000
Subject: LinHES-system: lh_system_backup_job: add Plex backup and excludes

change secondary backup to search if disk1 doesn't exist
---
 abs/core/LinHES-system/PKGBUILD             |  4 +--
 abs/core/LinHES-system/lh_system_backup_job | 43 ++++++++++++++++++++++++++---
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD
index 9c7d50b..602becc 100755
--- a/abs/core/LinHES-system/PKGBUILD
+++ b/abs/core/LinHES-system/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-system
 pkgver=8.4
-pkgrel=1
+pkgrel=2
 arch=('i686' 'x86_64')
 install=system.install
 pkgdesc="Everything that makes LinHES an automated system"
@@ -96,7 +96,7 @@ md5sums=('c03d5e54f00e404c561c7dc69fff9168'
          '33fbebbd546672cedd3c5e7350ab414e'
          'c773d8caacba8fbd4968e8afe5137bc6'
          '3edef50a49a47694bf8add39cc160add'
-         '8336874ee9e527f9799c3dec9fb770b5'
+         'a6b75b7953f6de6a5f6a2069b6229ec6'
          'bc69a520add58ede9b060c73e67ace13'
          '74e17d6f7453c52d56fecaed5c3f6ad5'
          '47e093e8cfe4b5b96602358e1f540832'
diff --git a/abs/core/LinHES-system/lh_system_backup_job b/abs/core/LinHES-system/lh_system_backup_job
index ca6800a..c7d7d9d 100644
--- a/abs/core/LinHES-system/lh_system_backup_job
+++ b/abs/core/LinHES-system/lh_system_backup_job
@@ -81,6 +81,24 @@ function backup(){
     echo "Backup func keys"
     cp -rp /etc/pki $BACKUPDIR/$DATE/pki
 
+    echo "Backup Plex Media Server databases and preferences"
+    if [ -e  /data/storage/disk0/media/plex/Plex\ Media\ Server/Plug-in\ Support ]
+    then
+        mkdir $BACKUPDIR/$DATE/plex
+        backup_status_check $?
+    fi
+    if [ -e  /data/storage/disk0/media/plex/Plex\ Media\ Server/Plug-in\ Support/Databases ]
+    then
+        cp -rp /data/storage/disk0/media/plex/Plex\ Media\ Server/Plug-in\ Support/Databases $BACKUPDIR/$DATE/plex/Databases
+        backup_status_check $?
+    fi
+    if [ -e  /data/storage/disk0/media/plex/Plex\ Media\ Server/Plug-in\ Support/Preferences ]
+    then
+        cp -rp /data/storage/disk0/media/plex/Plex\ Media\ Server/Plug-in\ Support/Preferences $BACKUPDIR/$DATE/plex/Preferences
+        backup_status_check $?
+    fi
+
+    #create default backup_exclude.txt
     if [ ! -f $MYTHHOME/backup_config/backup_exclude.txt ]
     then
         mkdir -p $MYTHHOME/backup_config/
@@ -88,7 +106,7 @@ function backup(){
         chmod 777 $MYTHHOME/backup_config/backup_exclude.txt
     fi
 
-    for i in ".mythtv/themecache" ".mythtv/remotecache" ".mythtv/Cache-myth*" ".cache" "tmp" ".vnc/*log" ".vnc/*pid"
+    for i in ".mythtv/themecache" ".mythtv/remotecache" ".mythtv/Cache-myth*" ".cache" "tmp" ".vnc/*log" ".vnc/*pid" ".plexht/userdata/Thumbnails" ".plexht/userdata/ThemeMusicCache" ".kodi/userdata/Thumbnails"
     do
         grep -qF "$i" $MYTHHOME/backup_config/backup_exclude.txt
         rc=$?
@@ -192,11 +210,28 @@ function remote_backup(){
             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 another drive on this system."
         SECBACKUPDISK=`readlink $SECBACKUPLINK`
-        SECBACKUP=$SECBACKUPDISK/backup
+
+        if [ -z $SECBACKUPDISK ]
+        then
+            for dir in /data/storage/disk*
+            do
+                if [ $dir == /data/storage/disk0 ]
+                then
+                    continue
+                fi
+                TESTDIR=`readlink $dir`
+                if [ -n $TESTDIR ]
+                then
+                    SECBACKUPDISK=$TESTDIR
+                    break
+                fi
+            done
+        fi
 
         if [ -n "$SECBACKUPDISK" ]; then
+            SECBACKUP=$SECBACKUPDISK/backup
             if [ `mountpoint -q -d $SECBACKUPDISK` ]; then
                 if [ ! -d "$SECBACKUP" ]; then
                     mkdir -p -m 775 $SECBACKUP
@@ -209,7 +244,7 @@ function remote_backup(){
                 echo "    $SECBACKUPDISK isn't mounted."
             fi
         else
-            echo "    Link $SECBACKUPLINK doesn't exist."
+            echo "    Could not find another drive on this system."
         fi
     fi
 }
-- 
cgit v0.12

