PicturesBackup3 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. #!/bin/bash
  2. ############
  3. ##
  4. ##THIS NEW SCRIPT WILL RESIDE ON TOMCAT AND DO THE FOLLOWING
  5. ##
  6. ##
  7. ##NEEDED UPGRADES
  8. ## Check if required servers are online
  9. ## If not, activate them via WOL, wait, anc check again
  10. ##
  11. ## 8/6/2019 - changed builtar to not use chown. Instead, use chgrp to change to familyshare
  12. ## MUST ensure sync function works with this change on ENTERPRISE!!
  13. ## This eliminates need for sudo to run script
  14. ##
  15. ## 2/19/21 - ADD FUNCTIONALITY TO BACKUP MYSQL DATABASE AND COMPRESS INTO TARBALL
  16. ##
  17. ## Build debian to place this script in either:
  18. ## - /.local for user
  19. ## - /usr/local/bin for global
  20. ## Symlink to /usr/local/bin for ease of use
  21. ##
  22. ## Interactive Menu Mode:
  23. ##
  24. ## If no flags passed, start interactive mode with promopts for:
  25. ## - What needs to be done (build tar, sync, or clean)
  26. ## - Based on result, what source and destintation (if syncing or building tar)
  27. ## -
  28. ##
  29. #############
  30. ## DEFINE VARIABLES ##
  31. DATE=$(date +%b-%d-%T)
  32. VERSION=0.1.2
  33. LOCALARCHIVEPATH=/storage/backup
  34. PIHOMEPATHTOFILES=/home/pi/ ## Folder containing data that will be backed up
  35. #PIHOMEPATHTOFILES=home/pi/scripts ## USE THIS PROFILE ONLY FOR TESTING- ARCHIVES ONLY A SMALL FOLDER
  36. PIHOMEFOLDER=PiHomeBackup ## Name of Folder that will store the archives
  37. PIHOMEFILENAME=PiHomeBackup-$DATE.tar.gz ## Filename structure for archives
  38. OWNCLOUDPATHTOFILES=storage/nextcloud/ ## Folder containing data that will be backed up
  39. #OWNCLOUDPATHTOFILES=storage/nextcloud/mike/files/Network ## Folder containing data that will be backed up
  40. OWNCLOUDFOLDER=PiOwncloudBackup ## Name of Folder that will store the archives
  41. OWNCLOUDFILENAME=PiOwncloudArchive-$DATE.tar.gz ## Filename structure for archives
  42. ENTERPRISESTORAGE=/storage/backup/
  43. ENTERPRISESHARE=/storage/ENTERPRISESHARE
  44. PCSHARE=/storage/PCSHARE
  45. PATHTOLOG=/var/log/TOMCAT.log
  46. VERBOSITY=2 ## Default Verbosity Normal (Debug Level 1 -C flag, Critical Level 3 -S flag)
  47. LOGLEVEL=1
  48. PIHOMEKEEPFILES=4 ## Number of local backups that will be kept after cleaning
  49. OWNCLOUDKEEPFILES=7 ## Number of local backups that will be kept after cleaning
  50. ## Arrays for servers to sync ##
  51. ## arrNAME=(Common Name, IP, remote folder to mount, local location for mount, username, password) ##
  52. arrENTERPRISE=(ENTERPRISE 192.168.100.27 /backup $ENTERPRISESHARE mike cherokee2)
  53. ##arrPC=(PC 192.168.100.51 /Mavrick_Pictures $PCSHARE NetworkUser cherokee2) ## <- Use for Windows
  54. arrPC=(PC 192.168.100.51 /PicturesBackup $PCSHARE mike cherokee2) ## <- Use for Linux
  55. ## FLAGS ##
  56. FLAGBUILD=0
  57. FLAGSYNC=0
  58. FLAGHOME=0
  59. FLAGOWNCLOUD=0
  60. FLAGPICTURES=0
  61. FLAGPHONE=0
  62. FLAGCLEAN=0 ## If 0, -C must be called to clean after archiving. If 1, cleaning will occur automatically
  63. FLAGTESTING=0 ## TEST MODE ACTIVE IF 1 OR HIGHER ##
  64. FLAGMYSQL=0
  65. ## END VARIABLES ##
  66. ## BEGIN FUNCTIONS ##
  67. addtolog () {
  68. ####LOG LEVELS####
  69. # Log levels:
  70. # 0 - Write to log file only
  71. # 1 - Write to Log file and screen at debug verbosity level (useful for debugging)
  72. # 2 - Write to Log file and screen at Normal Verbosity Level
  73. # 3 - Write to Log File and screen at CRITICAL Verbosity Level
  74. # default - level 1 (debgug verbosity)
  75. ##################
  76. if [ -z "$2" ]; then
  77. intLOGLEVEL="2" #if no variable passed, assume level 2
  78. else
  79. intLOGLEVEL="$2" #otherwise, use variable passed
  80. fi
  81. # echo "$intLOGLEVEL $VERBOSITY message: $1"
  82. DATESTAMP=$(date +%b-%d-%T)
  83. echo "$DATESTAMP | $USER | $1" >> $PATHTOLOG
  84. if [ $intLOGLEVEL -gt "0" ]; then #If verbosity level is greater than zero, pass message to write()
  85. write "$1" $intLOGLEVEL
  86. # echo "wrote $1"
  87. fi
  88. }
  89. write () {
  90. ##This function will write to the terminal screen based on the set VERBOSITY level##
  91. ##This function takes arguments [string] and intVERBOSITY"
  92. ## NEW PROTOCOL
  93. ##
  94. ## default verbosity (set by VERBOSITY flag = 2 (Normal Verbosity)
  95. ##
  96. ## -C argument sets verbosity to 0 (debug Verbosity) (show all higher than 0)
  97. ## -S argument sets verbosity to 3 (Silent / Only Critical Verbosity)
  98. ##
  99. ## Level 0 - Not used
  100. ## Level 1 - Debug Messages
  101. ## Level 2 - Normal (default)
  102. ## Level 3 - Critical
  103. ##
  104. ########
  105. if [ -z "$2" ]; then ##if no verbosity level is given, assume level 2 (default)
  106. intVERBOSE="2"
  107. else
  108. intVERBOSE="$2" ##Otherwise, use the provided verbosity level"
  109. fi
  110. # echo "write got $1 at $intVERBOSE with $VERBOSITY"
  111. if [ $intVERBOSE -ge $VERBOSITY ]; then
  112. echo "$1"
  113. fi
  114. }
  115. buildtar () {
  116. addtolog "buildtar: buildtar started for $1."
  117. case $1 in
  118. PiHome)
  119. FILENAME=$PIHOMEFOLDER/$PIHOMEFILENAME
  120. PATHTOFILES=$PIHOMEPATHTOFILES
  121. KEEPFILES=$PIHOMEKEEPFILES #Number of archives to keep on TOMCAT
  122. ;;
  123. Owncloud)
  124. FILENAME=$OWNCLOUDFOLDER/$OWNCLOUDFILENAME
  125. PATHTOFILES=$OWNCLOUDPATHTOFILES
  126. KEEPFILES=$OWNCLOUDKEEPFILES #Number of archives to keep on TOMCAT
  127. FLAGMYSQL=1
  128. ##
  129. ## ADD FUNCTIONALITY TO BACKUP MYSQL DATABASE
  130. ##
  131. ;;
  132. esac
  133. if [ ! $FLAGTESTING -gt "0" ]; then
  134. tar -czf $LOCALARCHIVEPATH/$FILENAME -C / $PATHTOFILES 2>> $PATHTOLOG
  135. if [ $FLAGMYSQL -gt "0" ]; then
  136. #### THIS FAILS BECAUSE TAR CANNOT ADD A FILE TO A GZIPPED TARBALL.
  137. #### MUST EITHER UNZIP ; ADD ; AND REZIP
  138. #### -- OR --
  139. #### ADD FILE _BEFORE_ ZIPPING SOMEHOW
  140. #### ALSO - Make sure OCC goes into mx mode BEFORE beginning archiving!
  141. addtolog "Beginning MySQL dump."
  142. sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on && addtolog "Nextcloud maintenance:mode --on" || addtolog "FAILED to activate Nextcloud maintenance:mode. Aborting MYSQL dump."
  143. mysqldump --single-transaction -u nextclouduser -pcherokee76 nextcloud > $LOCALARCHIVEPATH/$OWNCLOUDFOLDER/nextcloud_sql_bak`date +"%Y%m%d"`.bak
  144. sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off && addtolog "Nextcloud maintenance:mode --off" || addtolog "FAILED to de-activate Nextcloud maintenance:mode."
  145. tar -rf --force-local $LOCALARCHIVEPATH/$FILENAME $LOCALARCHIVEPATH/$OWNCLOUDFOLDER/nextcloud_sql_bak`date +"%Y%m%d"`.bak && addtolog "Added mysqldump to tar archive." || addtolog "FAILED to add mysql dump to tar archive."
  146. fi
  147. if [ "$?" = "0" ]; then
  148. addtolog "buildtar: successfully archived $PATHTOFILES to $LOCALARCHIVEPATH/$FILENAME"
  149. else
  150. addtolog "buildtar: FAILED to build .tar for $1."
  151. fi
  152. else
  153. addtolog "buildtar: TEST MODE: .tar not built"
  154. addtolog "buildtar: SIMULATED backup of $PATHTOFILES"
  155. addtolog "buildtar: SIMULATED archive built $LOCALARCHIVEPATH/$FILENAME"
  156. fi
  157. if [ ! $FLAGTESTING -gt 0 ]; then
  158. if [ "$EUID" -ne 0 ]; then
  159. chgrp familyshare $LOCALARCHIVEPATH/$FILENAME && addtolog "buildtar: set permissions on $FILENAME" || addtolog "buildtar: FAILED to set permissions on $FILENAME"
  160. else
  161. chown pi:familyshare $LOCALARCHIVEPATH/$FILENAME && addtolog "buildtar: set permissions on $FILENAME from root" || addtolog "buildtar: FAILED to change permissions on $FILENAME"
  162. fi
  163. else
  164. addtolog "Test Mode - File Permission change not attempted"
  165. fi
  166. if [ $FLAGCLEAN -gt "0" ]; then
  167. cleanfiles $1 $KEEPFILES
  168. fi
  169. }
  170. mountfiles () {
  171. echo "$(id -u)"
  172. addtolog "mountfiles: mountfiles started for $1."
  173. if mount | grep $4 > /dev/null; then
  174. addtolog "mountfiles: $1 files already mounted."
  175. else
  176. # sudo mount -t cifs //$2$3 $4 -o username=$5,password=$6 >> $PATHTOLOG 2>&1 &&
  177. # addtolog "mountfiles: successfully mounted $1 files." ||
  178. # addtolog "mountfiles: FAILED to mount $1." & failscript
  179. sudo mount -t cifs //$2$3 $4 -o username=$5,password=$6,uid=1000 >> $PATHTOLOG 2>&1
  180. if sudo mountpoint -q $4; then
  181. addtolog "mountfiles: successfully mounted $1 files."
  182. else
  183. addtolog "mountfiles: FAILED to mount $1." & failscript
  184. fi
  185. fi
  186. }
  187. unmountfiles () {
  188. addtolog "unmountfiles: unmountfiles started for $1."
  189. if mount | grep $4 > /dev/null; then
  190. sudo umount $4 &&
  191. addtolog "unmountfiles: successfully unmounted $1 files." ||
  192. addtolog "unmountfiles: FAILED to unmount $1"
  193. else
  194. addtolog "unmountfiles: $1 Files already unmounted."
  195. fi
  196. }
  197. checkpackage () {
  198. ## This script is used to check for the installation of other packages / scripts required
  199. ## returns 0 if package exists; 1 if package not found; fails if no variable passed
  200. if [ -z "$1" ]; then
  201. addtolog "checkpackages: Package Variable not received. Exiting" 3
  202. failscript
  203. else
  204. command -v $1 1>/dev/null 2>&1 && PACKAGEEXISTS=0 || PACKAGEEXISTS=1
  205. addtolog "checkpackages: Package $1 - flag set to $PACKAGEEXISTS" 1
  206. return $PACKAGEEXISTS
  207. fi
  208. }
  209. cleanfiles () {
  210. #####
  211. ## This Function will be run manually, or automatically after Tomcat builds a new Owncloud backup .tar file
  212. ## This Funtion take the following arguments:
  213. ## 1 - Name of server to clean (currently Enterprise or Owncloud)
  214. ## 2 - (optional) number of files to keep (default 4)
  215. ####
  216. if [ -z "$2" ]; then # If argument 2 is not set
  217. filestokeep=4 # Default to 4
  218. else
  219. filestokeep="$2" # Otherwise use argument
  220. fi
  221. addtolog "cleanfiles: cleanfiles started for $1. Keeping $filestokeep files."
  222. case $1 in
  223. Enterprise)
  224. ##This is a future upgrade
  225. ##Endure share is mounted
  226. ##Sort and delete files
  227. ##Log files deleted
  228. addtolog "Enterprise cleanfiles not available at this time." 3
  229. ;;
  230. PiHome)
  231. cleanpath="$LOCALARCHIVEPATH/$PIHOMEFOLDER"
  232. ;;
  233. Owncloud)
  234. cleanpath="$LOCALARCHIVEPATH/$OWNCLOUDFOLDER"
  235. ;;
  236. *)
  237. addtolog "Cannot call cleanfiles with $1" 3
  238. failscript
  239. esac
  240. arrFiles=($(ls -t -- $cleanpath/*.tar.gz 2>/dev/null))
  241. totalfiles=${#arrFiles[@]}
  242. addtolog "cleanfiles: found $totalfiles files in $cleanpath"
  243. if [ "$totalfiles" -le "$filestokeep" ]
  244. then
  245. addtolog "cleanfiles will not delete files on $cleanpath. Total Files is less than or equal to $filestokeep"
  246. else
  247. filestoremove=$((totalfiles - filestokeep))
  248. addtolog "cleanfiles will attempt to remove the oldest $filestoremove files"
  249. for index in "${!arrFiles[@]}"
  250. do
  251. if [ "$index" -gt "$((filestokeep - 1))" ]; then
  252. #Array is 0 based, so -1
  253. if [ $FLAGTESTING -lt "1" ]; then #Do Nothing if Testing flag is set true
  254. rm -f ${arrFiles[$index]}
  255. addtolog "cleanfiles: DELETED: ${arrFiles[$index]}"
  256. else
  257. addtolog "cleanfiles: TEST MODE | SIMULATED DELETE: ${arrFiles[$index]}"
  258. fi
  259. fi
  260. done
  261. fi
  262. }
  263. syncfiles () {
  264. addtolog "syncfiles: syncfiles started for $1."
  265. # determine server shares needed and file paths
  266. SOURCEPATH=$LOCALARCHIVEPATH
  267. DESTPATH=$ENTERPRISESHARE
  268. case $1 in
  269. PiHome)
  270. SOURCEPATH=${SOURCEPATH}/$PIHOMEFOLDER/$PIHOMEFILENAME
  271. DESTPATH=${DESTPATH}/TOMCAT/PiHomeDir/
  272. # DESTPATH=/home/pi/
  273. mountfiles ${arrENTERPRISE[@]}
  274. ;;
  275. Owncloud)
  276. SOURCEPATH=${SOURCEPATH}/$OWNCLOUDFOLDER/
  277. DESTPATH=${DESTPATH}/TOMCAT/Owncloud/
  278. mountfiles ${arrENTERPRISE[@]}
  279. ;;
  280. Pictures)
  281. SOURCEPATH=$PCSHARE/
  282. DESTPATH=${DESTPATH}/Pictures/
  283. mountfiles ${arrENTERPRISE[@]}
  284. mountfiles ${arrPC[@]}
  285. ;;
  286. phone)
  287. SOURCEPATH=/storage/backup/phone/mike/
  288. DESTPATH=${DESTPATH}/TOMCAT/phone/mike/
  289. mountfiles ${arrENTERPRISE[@]}
  290. esac
  291. # Perform rsync
  292. # echo "$DATE | syncfiles: I will rsync $SOURCEPATH to $DESTPATH"
  293. addtolog "syncfiles: syncing $SOURCEPATH to $DESTPATH." 3
  294. rsync -avP --no-o --no-g --stats --progress --chown=mike:mike $SOURCEPATH $DESTPATH 2>> $PATHTOLOG &&
  295. ## rsync modified 2/9/2019 to remove -z flag. This will eliminate rsync compression
  296. ## and should lead to faster trasnfers
  297. addtolog "syncfiles: successfully rsynced $SOURCEPATH to $DESTPATH." 3 ||
  298. addtolog "syncfiles: FAILED to rsync $SOURCEPATH to $DESTPATH." 3
  299. unmountfiles ${arrENTERPRISE[@]}
  300. unmountfiles ${arrPC[@]}
  301. }
  302. checkusersudo () {
  303. ## For Some operations, user must have sudo privileges
  304. ## This will check for sudo
  305. ## and stop script if user need additional privileges
  306. if [ "$EUID" -ne 0 ]; then
  307. MESSAGE="Must run as sudo. This program requires sudo privileges to archive Owncloud files."
  308. addtolog "$MESSAGE" 3
  309. failscript
  310. fi
  311. }
  312. startscript() {
  313. #Prepare Log file for new execution#
  314. addtolog "---------------------------------------------------------" 0
  315. addtolog "$0 Script starting" 3
  316. }
  317. failscript() {
  318. addtolog "$0 script failed. Exiting." 3
  319. addtolog "--------------------------------------------------------" 0
  320. exit 1
  321. }
  322. endscript() {
  323. addtolog "$0 script complete. Exiting." 3
  324. addtolog "---------------------------------------------------------" 0
  325. exit 0
  326. }
  327. ###############
  328. # HELP FILE #
  329. ###############
  330. display_help() {
  331. echo "This script will build .tar archives of the Pi Home Directory and Owncloud files, and can sync archives and PC pictures folder to ENTERPRISE."
  332. echo " "
  333. echo " -h This help file"
  334. echo " -B, Build .tar files"
  335. echo " -S, Sync files between machines"
  336. echo " -C, Cleanup. Used to manually clean acrchives. Normally automatic with -B or -S"
  337. echo " -p, Perform actions on PiHome Directory"
  338. echo " -o, Perform actions on Owncloud"
  339. echo " -i, Perform actions on Photos"
  340. echo " -t, Perform actions on Phone Backup"
  341. echo " -T, Testing Mode. No Deletions"
  342. echo " -m, Mount filesystems only (used for testing)"
  343. echo " -u, Unmount filesystems only (used for testing)"
  344. echo " -s, Silent Mode. Supress all output except errors."
  345. echo " -V, Verbose Mode. Show all debugging on screen."
  346. echo " -v, Version. Display Version information."
  347. echo
  348. addtolog "$0 help menu displayed." 0
  349. }
  350. ##############
  351. # END HELP #
  352. ##############
  353. trap ctrl_c 2 3 6 15
  354. ctrl_c () {
  355. addtolog "SIGINT CTRL_C. Unmounting files and stopping." 3
  356. addtolog "Aborting Script. Waiting for processes to finish." 3
  357. sleep 2
  358. addtolog "Unmounting file shares" 3
  359. sleep 2
  360. unmountfiles ${arrENTERPRISE[@]} && addtolog "Enterpise unmounted" || addtolog "Failed to unmount ENTERPRISE" 3
  361. unmountfiles ${arrPC[@]} && addtolog "PC unmounted" || addtolog "Failed to unmount PC" 3
  362. addtolog "$0 Script has stopped. Exiting." 3
  363. exit 1
  364. }
  365. startscript
  366. startlog="$0 script starting with the commands:"
  367. options=':hBSCpoitmusTVv'
  368. while getopts $options option
  369. do
  370. case $option in
  371. h ) startlog="$startlog help menu"
  372. addtolog "$startlog"
  373. display_help
  374. endscript;;
  375. s ) startlog="$startlog silent mode "
  376. VERBOSITY=0;;
  377. V ) startlog="$startlog verbose mode "
  378. VERBOSITY=2;;
  379. B ) FLAGBUILD=1
  380. startlog="$startlog BUILD ";;
  381. S ) FLAGSYNC=1
  382. echo $index
  383. echo $index
  384. echo $index
  385. echo $index
  386. echo $index
  387. startlog="$startlog SYNC ";;
  388. C ) startlog="$startlog CLEANUP "
  389. FLAGCLEAN=1;;
  390. p ) FLAGHOME=1
  391. startlog="$startlog PiHome ";;
  392. o ) FLAGOWNCLOUD=1
  393. startlog="$startlog owncloud ";;
  394. i ) FLAGPICTURES=1
  395. startlog="$startlog PC Pictures ";;
  396. t ) FLAGPHONE=1
  397. startlog="$startlog, Phone Backup ";;
  398. T ) FLAGTESTING=1
  399. startlog="$startlog TESTING MODE";;
  400. m ) startlog="$startlog mount files only"
  401. echo "mounting"
  402. addtolog "$startlog"
  403. mountfiles ${arrENTERPRISE[@]}
  404. mountfiles ${arrPC[@]}
  405. endscript;;
  406. u ) startlog="$startlog unmount files only"
  407. addtolog "$startlog"
  408. unmountfiles ${arrENTERPRISE[@]}
  409. unmountfiles ${arrPC[@]}
  410. endscript;;
  411. v ) startlog="$startlog, Display Version - $VERSION"
  412. echo "$0 - Version $VERSION"
  413. # addtolog "$startlog"
  414. # endscript
  415. exit 0;;
  416. * ) display_help
  417. endscript ;;
  418. /? ) addtolog "unknown menu option $1. Exiting." 3; exit 1;;
  419. esac
  420. done
  421. ## Check is Options were passed
  422. ## If not, consider Interactive mode
  423. if [ $OPTIND -eq 1 ]; then addtolog "No options were passed in command line." 1; fi
  424. ##
  425. addtolog "$startlog" 3
  426. ####################
  427. # DONE ARGUMENTS #
  428. ####################
  429. ####################
  430. # RUN CHECKS #
  431. ####################
  432. if [ $FLAGTESTING -gt "0" ]; then
  433. VERBOSITY=0
  434. addtolog "**TESTING MODE ACTIVE**" 3
  435. addtolog "Verbose mode implied by testing mode" 3
  436. echo "Set Verbosity to $VERBOSITY"
  437. # if [ $FLAGCLEAN -gt "0" ]; then
  438. # cleanfiles Owncloud $OWNCLOUDKEEPFILES
  439. # fi
  440. fi
  441. ## Check for existance of WOL2 package for sync operations ##
  442. checkpackage wol2 || addtolog "wol2 Package not found. Needed for sync operations." 1
  443. ## Check SYNC or BUILD flags have appropriate action##
  444. if [ $FLAGSYNC -eq "1" -o $FLAGBUILD -eq "1" ]; then
  445. if ! [ $FLAGHOME -eq "1" -o $FLAGOWNCLOUD -eq "1" -o $FLAGPICTURES -eq "1" -o $FLAGPHONE -eq "1" ]; then
  446. addtolog "FAIL: FLAGSYNC or FLAGBUILD did not have -p,o,i, or t action declared. See -h for help." 3
  447. exit 1
  448. fi
  449. fi
  450. ###################
  451. # END CHECKS #
  452. ###################
  453. ###################
  454. # BEGIN ACTIONS #
  455. ###################
  456. ## Check PiHome Flag ##
  457. if [ $FLAGHOME -eq "1" ]; then
  458. ##Perform actiong on PiHome Directory
  459. addtolog "Perform Actions on PiHomeDirectory" 1
  460. if [ $FLAGBUILD -eq "1" ]; then
  461. addtolog "Perform Tar Build on PiHomeDirectory" 1
  462. buildtar PiHome
  463. fi
  464. if [ $FLAGSYNC -eq "1" ]; then
  465. addtolog "Perform Sync on PiHomeDirectory" 1
  466. ##PERFORM ACTIONS TO SYNC FILES##
  467. syncfiles PiHome
  468. fi
  469. fi
  470. ## Check Owncloud Flag ##
  471. if [ $FLAGOWNCLOUD -eq "1" ]; then
  472. ##Perform action on Owncloud Directory
  473. if [ $FLAGBUILD -eq "1" ]; then
  474. checkusersudo && buildtar Owncloud
  475. fi
  476. if [ $FLAGSYNC -eq "1" ]; then
  477. #echo "Perform Sync on Owncloud Directory"
  478. ##PERFORM ACTIONS TO SYNC FILES##
  479. syncfiles Owncloud
  480. fi
  481. fi
  482. ## Check Pictures Flag ##
  483. if [ $FLAGPICTURES -eq "1" ]; then
  484. ##Perform action on Pictures Directory
  485. #echo "Perform Actions on Pictrues Directory"
  486. if [ $FLAGBUILD -eq "1" ]; then
  487. addtolog "Cannot Perform Compression of Pictures. Sync only. Exiting." 3
  488. endscript
  489. fi
  490. if [ $FLAGSYNC -eq "1" ]; then
  491. #echo "Perform Sync on Pictures"
  492. ##PERFORM ACTIONS TO SYNC FILES##
  493. syncfiles Pictures
  494. fi
  495. fi
  496. ## Check Phone Flag ##
  497. if [ $FLAGPHONE -eq "1" ]; then
  498. ##Perform actiong on Phone Directory
  499. #echo "Perform Actions on Phone Backup Directory"
  500. if [ $FLAGBUILD -eq "1" ]; then
  501. addtolog "Cannot build archive of Phone Backup. Sync only. Exiting." 3
  502. endscript
  503. fi
  504. if [ $FLAGSYNC -eq "1" ]; then
  505. # echo "Cannot Sync Phone Backup Files. FUTURE UPGRADE"
  506. syncfiles phone
  507. fi
  508. fi
  509. #################
  510. # END ACTIONS #
  511. #################
  512. endscript