snickasaurus

Rsync to FreeNAS

Feb 17th, 2018
103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Name     : Rsync-to-FreeNAS.sh
  4. # Author   : Snickasaurus
  5. # Date     : 20180217
  6. # Purpose  : Rsync files to FreeNAS.
  7. # Requires : The "macmini1.txt" in the same dir as this script.
  8.  
  9. # Variables
  10. currentUser=$(ls -l /dev/console | cut -d " " -f 4)
  11. currentLogFile=/Users/"${currentUser}"/Library/Logs/_MyLogs/rSyncFreeNAS-.log
  12. theDestination=/Volumes/Backups/Config/
  13. theSerial=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
  14.  
  15. # Functions
  16. function currentTime(){
  17.     date "+%Y%m%d-%H%M%S"
  18. }
  19.  
  20. # Log Directory Check
  21. if [ ! -d /Users/"$currentUser"/Library/Logs/_MyLogs ]
  22.     then
  23.     mkdir /Users/"$currentUser"/Library/Logs/_MyLogs
  24. fi
  25.  
  26. # Backup Directory Check
  27. if [ ! -d /Volumes/Backups/Config/"$theSerial" ]
  28.     then
  29.     mkdir /Volumes/Backups/Config/"$theSerial"
  30. fi
  31.  
  32. # Logging
  33. exec 3>&1 4>&2
  34. trap 'exec 2>&4 1>&3' 0 1 2 3
  35. exec 1>>"$currentLogFile" 2>&1
  36.  
  37. # Backup starting.
  38. echo "=====Starting @ "$(date "+%H:%M:%S  %Y/%m/%d")" ====="
  39. echo " "
  40. echo " "
  41.  
  42. # Start the rSync tool.
  43. /usr/bin/rsync -avzEh --delete --stats --files-from=./macmini1.txt --exclude=".DS_Store" / "$theDestination"/"$theSerial"
  44.  
  45. # Backup completed.
  46. echo " "
  47. echo " "
  48. echo "=====Completed @ "$(date "+%H:%M:%S  %Y/%m/%d")" ====="
  49.  
  50. # Rename the log file.
  51. cd /Users/"$currentUser"/Library/Logs/_MyLogs && /bin/mv rSyncFreeNAS-.log rSyncFreeNAS-"$(currentTime)".log
  52.  
  53. # Prune old logs
  54. find /Users/"$currentUser"/Library/Logs/_MyLogs/rSyncFreeNAS-*.log -maxdepth 1 -type f -mtime +30 -delete
  55.  
  56. exit 0
RAW Paste Data Copied