You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
6.3KB

  1. #!/bin/bash
  2. # 345678901234567892123456789312345678941234567895123456789612345678971234567898
  3. # mac homedir backup script.
  4. # by jeffrey paul <sneak@datavibe.net>
  5. # 5539 AD00 DE4C 42F3 AFE1 1575 0524 43F4 DF2A 55C2
  6. # see README
  7. NOW="`date +%Y%m%d.%H%M%S`"
  8. BACKUPDEST=${BACKUPDEST:-"/Volumes/ExternalBackup/sneak.backup"}
  9. RSYNC_SKIP_COMPRESS="3fr/3g2/3gp/3gpp/7z/aac/ace/amr/apk/appx/appxbundle"
  10. RSYNC_SKIP_COMPRESS+="/arc/arj/arw"
  11. RSYNC_SKIP_COMPRESS+="/asf/avi/bz2/cab/cr2/crypt[5678]/dat/dcr/deb/dmg/drc/ear"
  12. RSYNC_SKIP_COMPRESS+="/erf/flac/flv/gif/gpg/gz/iiq/iso/jar/jp2/jpeg/jpg/k25/kdc"
  13. RSYNC_SKIP_COMPRESS+="/lz/lzma/lzo/m4[apv]/mef/mkv/mos/mov/mp[34]/mpeg"
  14. RSYNC_SKIP_COMPRESS+="/mp[gv]/msi"
  15. RSYNC_SKIP_COMPRESS+="/nef/oga/ogg/ogv/opus/orf/pef/png/qt/rar/rpm/rw2/rzip/s7z"
  16. RSYNC_SKIP_COMPRESS+="/sfx/sr2/srf/svgz/t[gb]z/tlz/txz/vob/wim/wma/wmv/xz/zip"
  17. RSYNC="rsync"
  18. RSYNC_TRY="$HOME/Library/Homebrew/bin/rsync"
  19. if which brew >/dev/null 2>&1 ; then
  20. RSYNC_TRY="$(brew --prefix)/bin/rsync"
  21. fi
  22. if [[ -e "$RSYNC_TRY" ]]; then
  23. RSYNC="$RSYNC_TRY"
  24. fi
  25. #OPTS="-rlptDPSyzh --numeric-ids --no-owner --no-group --delete-excluded --delete"
  26. OPTS=""
  27. OPTS+=" -avP --skip-compress=$RSYNC_SKIP_COMPRESS"
  28. OPTS+=" --numeric-ids --no-owner --no-group --delete-excluded --delete-after"
  29. RE=""
  30. RE+=" --exclude=.bundle/"
  31. RE+=" --exclude=.cache/"
  32. RE+=" --exclude=/.cpan/build/"
  33. RE+=" --exclude=/.cpan/sources/"
  34. RE+=" --exclude=/.docker/"
  35. RE+=" --exclude=/.dropbox/"
  36. RE+=" --exclude=/.minikube/cache/"
  37. RE+=" --exclude=/Desktop/" # desktop is like a visible tempdir.
  38. RE+=" --exclude=/Library/VoiceTrigger/SAT"
  39. RE+=" --exclude=/Documents/Dropbox/.dropbox.cache/"
  40. RE+=" --exclude=/Documents/Steam?Content/"
  41. RE+=" --exclude=/Downloads/"
  42. RE+=" --exclude=/Library/Application?Support/Ableton/"
  43. RE+=" --exclude=/Library/Application?Support/Adobe/Adobe?Device?Central?CS4/"
  44. RE+=" --exclude=/Library/Application?Support/CrossOver?Games/"
  45. RE+=" --exclude=/Library/Application?Support/Evernote/" # syncs to cloud
  46. RE+=" --exclude=/Library/Application?Support/InsomniaX/"
  47. RE+=" --exclude=/Library/Application?Support/MobileSync/"
  48. RE+=" --exclude=/Library/Application?Support/SecondLife/cache/"
  49. RE+=" --exclude=/Library/Application?Support/Steam/SteamApps/"
  50. RE+=" --exclude=/Library/Application?Support/SyncServices/"
  51. RE+=" --exclude=/Library/Caches/"
  52. RE+=" --exclude=/Library/Containers/com.docker.docker/"
  53. RE+=" --exclude=/Library/Cookies/"
  54. RE+=" --exclude=/Library/Developer/"
  55. RE+=" --exclude=/Library/Homebrew/"
  56. RE+=" --exclude=/Library/Syncthing/folders/" # syncthing is its own backup
  57. RE+=" --exclude=/Library/Logs/"
  58. RE+=" --exclude=/Library/Mail/" # keep your mail on the server!
  59. RE+=" --exclude=/Library/Mail?Downloads/"
  60. RE+=" --exclude=/Library/Preferences/Macromedia/Flash?Player/"
  61. RE+=" --exclude=/Library/Preferences/SDMHelpData/"
  62. RE+=" --exclude=/Library/PubSub/"
  63. RE+=" --exclude=/Library/Safari/"
  64. RE+=" --exclude=/Library/Safari/HistoryIndex.sk"
  65. RE+=" --exclude=/Library/iTunes/iPad?Software?Updates/"
  66. RE+=" --exclude=/Library/iTunes/iPhone?Software?Updates/"
  67. RE+=" --exclude=/Music/iTunes/Album?Artwork/"
  68. RE+=" --exclude=/Pictures/iPod?Photo?Cache/"
  69. RE+=" --exclude=/Receivd/"
  70. RE+=" --exclude=/VirtualBox?VMs/"
  71. # apps in homedir
  72. RE+=" --exclude=/Applications/Fortnite/"
  73. MINRE=""
  74. MINRE+=" --exclude=/.fseventsd/"
  75. MINRE+=" --exclude=/.Spotlight-V100/"
  76. MINRE+=" --exclude=/.Trash/"
  77. MINRE+=" --exclude=/.Trashes/"
  78. MINRE+=" --exclude=/tmp/"
  79. MINRE+=" --exclude=/.TemporaryItems/"
  80. MINRE+=" --exclude=/.rnd/"
  81. MINRE+=" --exclude=.DS_Store"
  82. RE+=" ${MINRE}"
  83. echo "beginning backup to '$BACKUPDEST'..."
  84. RETVAL=255
  85. while [ $RETVAL -ne 0 ]; do
  86. $RSYNC $OPTS $RE ${HOME}/ ${BACKUPDEST}/home.$(whoami)/
  87. RETVAL=$?
  88. sleep 1;
  89. done
  90. RE=""
  91. RE+=" --exclude=/.DS_Store"
  92. RE+=" --exclude=/App?Store.app"
  93. RE+=" --exclude=/Automator.app"
  94. RE+=" --exclude=/Books.app"
  95. RE+=" --exclude=/Calculator.app"
  96. RE+=" --exclude=/Calendar.app"
  97. RE+=" --exclude=/Chess.app"
  98. RE+=" --exclude=/Contacts.app"
  99. RE+=" --exclude=/DVD?Player.app"
  100. RE+=" --exclude=/Dashboard.app"
  101. RE+=" --exclude=/Dictionary.app"
  102. RE+=" --exclude=/FaceTime.app"
  103. RE+=" --exclude=/Font?Book.app"
  104. RE+=" --exclude=/Game?Center.app"
  105. RE+=" --exclude=/GarageBand.app"
  106. RE+=" --exclude=/Home.app"
  107. RE+=" --exclude=/Image?Capture.app"
  108. RE+=" --exclude=/Install?OS?X?El?Capitan.app"
  109. RE+=" --exclude=/Install?OS?X?Yosemite.app"
  110. RE+=" --exclude=/Keynote.app"
  111. RE+=" --exclude=/Launchpad.app"
  112. RE+=" --exclude=/Mail.app"
  113. RE+=" --exclude=/Maps.app"
  114. RE+=" --exclude=/Messages.app"
  115. RE+=" --exclude=/Mission?Control.app"
  116. RE+=" --exclude=/News.app"
  117. RE+=" --exclude=/Notes.app"
  118. RE+=" --exclude=/Numbers.app"
  119. RE+=" --exclude=/Pages.app"
  120. RE+=" --exclude=/Photo?Booth.app"
  121. RE+=" --exclude=/Photos.app"
  122. RE+=" --exclude=/Preview.app"
  123. RE+=" --exclude=/QuickTime?Player.app"
  124. RE+=" --exclude=/Reminders.app"
  125. RE+=" --exclude=/Safari.app"
  126. RE+=" --exclude=/Siri.app"
  127. RE+=" --exclude=/Spotify.app"
  128. RE+=" --exclude=/Steam.app"
  129. RE+=" --exclude=/Stocks.app"
  130. RE+=" --exclude=/Stickies.app"
  131. RE+=" --exclude=/System?Preferences.app"
  132. RE+=" --exclude=/TextEdit.app"
  133. RE+=" --exclude=/Time?Machine.app"
  134. RE+=" --exclude=/Utilities/Activity?Monitor.app"
  135. RE+=" --exclude=/Utilities/AirPort?Utility.app"
  136. RE+=" --exclude=/Utilities/AppleScript?Editor.app"
  137. RE+=" --exclude=/Utilities/Audio?MIDI?Setup.app"
  138. RE+=" --exclude=/Utilities/Bluetooth?File?Exchange.app"
  139. RE+=" --exclude=/Utilities/Boot?Camp?Assistant.app"
  140. RE+=" --exclude=/Utilities/ColorSync?Utility.app"
  141. RE+=" --exclude=/Utilities/Console.app"
  142. RE+=" --exclude=/Utilities/Digital?Color?Meter.app"
  143. RE+=" --exclude=/Utilities/DigitalColor?Meter.app"
  144. RE+=" --exclude=/Utilities/Disk?Utility.app"
  145. RE+=" --exclude=/Utilities/Grab.app"
  146. RE+=" --exclude=/Utilities/Grapher.app"
  147. RE+=" --exclude=/Utilities/Keychain?Access.app"
  148. RE+=" --exclude=/Utilities/Migration?Assistant.app"
  149. RE+=" --exclude=/Utilities/Screenshot.app"
  150. RE+=" --exclude=/Utilities/Script?Editor.app"
  151. RE+=" --exclude=/Utilities/System?Information.app"
  152. RE+=" --exclude=/Utilities/Terminal.app"
  153. RE+=" --exclude=/Utilities/VoiceOver?Utility.app"
  154. RE+=" --exclude=/VirtualBox.app"
  155. RE+=" --exclude=/VoiceMemos.app"
  156. RE+=" --exclude=/Xcode.app"
  157. RE+=" --exclude=/iBooks.app"
  158. RE+=" --exclude=/iMovie.app"
  159. RE+=" --exclude=/iTunes.app"
  160. if [[ "$(uname)" = "Darwin" ]]; then
  161. RETVAL=255
  162. while [ $RETVAL -ne 0 ]; do
  163. $RSYNC $OPTS $RE $MINRE /Applications/ ${BACKUPDEST}/Applications/
  164. RETVAL=$?
  165. sleep 1;
  166. done
  167. fi