Bandit Design » Our Design Our Portfolio Contact Us
Tutorials TumbleLog Our Thoughts
Quite often at Bandit Design while we're working on your project, we'll stumble upon interesting or humourous things -- so we thought why not share them with the world!
RSS iPhone Random Archive « Home

Bandit Design

This is a TumbleLog authored at the desks of Bandit Design. We're a small web and graphic design studio based in Wellington, New Zealand.

Visit Bandit Design »

1 year ago

HowTo: Automatic Custom Daily Backup on OSX

Just wrote an OSX script to automate my daily backups on OSX. I simply backup all of the important files and settings that I have at 11am and 4pm each day to a folder called Backup, which I then back up to S3 using the epic Arq;

  1. Open a Terminal window - don’t worry if you’re not used to it, neither am I!
  2. Create and edit a file called osx-backup-script.sh somewhere; sudo nano ~/osx-backup-script.sh
  3. Add the following code to it (be sure to change USER to your OSX username!):
    
    #!/bin/sh
    
    # otherwise mysqldump won't work
    export PATH=/usr/local/mysql/bin:$PATH
    
    # YOUR USERNAME
    USER=bandit
    DATE=`date "+%Y-%m-%d_%H-%M"`
    
    # PHOTOSHOP
    sudo rsync -axS --delete $* "/Users/$USER/Library/Preferences/Adobe Photoshop CS5 Settings/WorkSpaces/" "/Users/$USER/Backup/Adobe Photoshop/"
    
    # APACHE
    sudo rsync -axS --delete $* "/etc/apache2/" "/Users/$USER/Backup/Apache/"
    sudo cat /etc/hosts > "/Users/$USER/Backup/Webstack/hosts.txt"
    
    # CODA
    sudo rsync -axS --delete $* "/Applications/Coda.app" "/Users/$USER/Backup/Coda/"
    sudo rsync -axS --delete $* --include="*panic.Coda*.plist" --exclude=* "/Users/$USER/Library/Preferences/" "/Users/$USER/Backup/Coda/Library/Preferences/"
    
    # GOOGLE CHROME
    sudo rsync -axS --delete $* "/Applications/Google Chrome.app" "/Users/$USER/Backup/Google Chrome/"
    sudo rsync -axS --delete $* --include="*google.Chrome*.plist" --exclude=* "/Users/$USER/Library/Preferences/" "/Users/$USER/Backup/Google Chrome/Library/Preferences/"
    sudo rsync -axS --delete $* "/Users/$USER/Library/Application Support/Google/Chrome/" "/Users/$USER/Backup/Google Chrome/Library/Application Support/Google/Chrome/"
    
    # LAUNCHBAR
    sudo rsync -axS --delete $* "/Applications/LaunchBar.app" "/Users/$USER/Backup/Launch Bar/"
    sudo rsync -axS --delete $* "/Users/$USER/Library/Application Support/LaunchBar/" "/Users/$USER/Backup/Launch Bar/Library/"
    
    # ARQ
    sudo rsync -axS --delete $* "/Users/$USER/Library/Arq/" "/Users/$USER/Backup/Arq/"
    
    # KEYCHAIN
    sudo rsync -axS --delete $* "/Users/$USER/Library/Keychains/" "/Users/$USER/Backup/Keychains/"
    
    # MYSQL Dump
    mysqldump --user=root --all-databases > /Users/$USER/Backup/MySQL/mysql_dump_$DATE.sql 2> /tmp/mycronerrorfile
    sudo gzip -f "/Users/$USER/Backup/MySQL/mysql_dump_$DATE.sql"
    
    # Delete all dumps older than 3 days
    sudo find /Users/$USER/Backup/MySQL -name *.* -mtime +3 -delete
    
    # CREATE LAST UPDATE FLAG
    sudo echo "Last updated: $DATE" > "/Users/$USER/Backup/.last_updated"
    
    
  4. I assume that everything should be stored in a folder called Backup in your home directory - you can change this easily by editing each line.
  5. I also assume that the MySQL database allows access using root with no password.
  6. Feel free to add more stuff to backup - that’s just what I use
  7. Change its access permissions; chmod u+x ~/osx-backup-script.sh;
  8. Time to automate! Type export EDITOR=nano; (to use a easier crontab editor)
  9. Enter sudo crontab -e; (you can use crontab -e; if your user is in the sudoers file)
  10. Once the crontab loads up, type in: 0   11,16   *   *   *   sudo sh /Users/bandit/osx-backup-script.sh on its own line, and don’t forget to put in your own username instead of “bandit”!
  11. You’re done! Your files should now backup at 11am and 4pm each day to a folder called Backup in your home folder :-)
  12. Now you can use Arq to back that folder up to S3 (which will cost you like $1.50/month!)
1 note

Loading...