Skip to content

Instantly share code, notes, and snippets.

@peterkappus
Created July 10, 2016 22:00
Show Gist options
  • Save peterkappus/a23b92d4517ab3483b535cb7295426e0 to your computer and use it in GitHub Desktop.
Save peterkappus/a23b92d4517ab3483b535cb7295426e0 to your computer and use it in GitHub Desktop.
A backup script to backup various things to my USB Drive
#!/usr/bin/ruby
#copy ~/Library/keychain
#for testing
rsync_flags = "avzn --delete"
#for real...
#--delete => delete files which don't exist in the source
rsync_flags = "avz --delete"
remote = "/Volumes/Thor/nemo_backup"
#backup apple keychain items
`mkdir -p #{remote}/Library/Keychains`
`rsync -#{rsync_flags} ~/Library/Keychains/ #{remote}/Library/Keychains`
#backup this script
`rsync -#{rsync_flags} ~/manual_backup.rb #{remote}/`
#various directories to backup
dirs = "Music Pictures Sites Dropbox Reference Desktop".split(' ')
#backup each one.
#NOTE: the trailing slash on the source prevents the directory from being recreated at the destination
dirs.each do |dir|
cmd = "rsync -#{rsync_flags} ~/#{dir} #{remote}"
puts cmd
puts `#{cmd}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment