Tutorials TumbleLog Our Thoughts
Bandit Design » Our Portfolio Our Design Contact Us
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 ยป

6 months 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
    
    # YOUR USERNAME
    USER=bandit
    
    # PHOTOSHOP
    sudo rsync -axS --delete $* "/Users/$USER/Library/Preferences/Adobe Photoshop CS4 Settings/WorkSpaces/" "/Users/$USER/Backup/Adobe Photoshop/"
    
    # APACHE
    sudo rsync -axS --delete $* "/etc/apache2/" "/Users/$USER/Backup/Apache/"
    
    # CODA
    sudo rsync -axS --delete $* "/Applications/Coda.app" "/Users/$USER/Backup/Coda/"
    sudo rsync -axS --delete $* --exclude=**/* --include="*panic.Coda*.plist" "/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 $* --exclude=**/* --include="*google.Chrome*.plist" "/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/"
    
    # MYSQL Physical Data
    sudo rsync -axS --delete $* "/usr/local/mysql/data/cyclenow" "/Users/$USER/Backup/MySQL/data"
    sudo chmod +r+x "/Users/$USER/Backup/MySQL/data/cyclenow"
    #sudo chown $USER:staff "/Users/$USER/Backup/MySQL/data/cyclenow"
    
    # MYSQL Dump
    sudo mysqldump --user=root --all-databases > "/Users/$USER/Backup/MySQL/mysql_dump.sql" | tar -cvf "/Users/$USER/Backup/MySQL/mysql_dump.sql.tar" "/Users/$USER/Backup/MySQL/mysql_dump.sql" | gzip -f "/Users/$USER/Backup/MySQL/mysql_dump.sql.tar"
    sudo rm "/Users/$USER/Backup/MySQL/mysql_dump.sql"
    
  4. Feel free to add more stuff to backup - that’s just what I use
  5. Change its access permissions; chmod u+x ~/osx-backup-script.sh;
  6. Time to automate! Type export EDITOR=nano;
  7. Enter crontab -e; (if you have problems later try entering sudo crontab -e; at this step)
  8. Once the crontab loads up, type in: * 11,16 * * * sudo /Users/bandit/Documents/Work/osx-backup-script.sh on its own line, and don’t forget to put in your own username instead of “bandit”!
  9. You’re done! Your files should now backup at 11am and 4pm each day to a folder called Backup in your home folder :-)
  10. Now you can use Arq to back that folder up to S3 which costs you like $0.50/month!

Loading...