SHARE
TWEET

script to backup address book on os x

a guest Aug 20th, 2011 157 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Backup addressbook on OS X to a specified folder
  4.  
  5. BACKUP_TARGET_DIR="$HOME/Dropbox/Backups"
  6.  
  7. # There should be no reason to change this
  8. BACKUP_SOURCE_DIR="$HOME/Library/Application Support/Addressbook"
  9.  
  10. # If you want you can change the name of the backup (folder)
  11. BACKUP_NAME="`date +%Y-%m-%d_%H.%M.%S`.abbu"
  12.  
  13. E_CD=86 # Can't change folder
  14.  
  15. # validate backup target dir
  16. cd $BACKUP_TARGET_DIR
  17.  
  18. if [ `pwd` != "$BACKUP_TARGET_DIR" ]
  19.         then
  20.         echo "Can't change to backup target folder $BACKUP_TARGET_DIR. Does it exist?"
  21.         exit $E_CD
  22. fi
  23.  
  24. mkdir -p "$BACKUP_TARGET_DIR/$BACKUP_NAME"
  25.  
  26. cd "$BACKUP_TARGET_DIR/$BACKUP_NAME"
  27.  
  28. if [ `pwd` != "$BACKUP_TARGET_DIR/$BACKUP_NAME" ]  
  29. then
  30.   echo "Can't change to backup folder $BACKUP_TARGET_DIR/$BACKUP_NAME"
  31.   exit $E_CD
  32. fi  
  33.  
  34. # Copy from $BACKUP_SOURCE_DIR
  35.  
  36. # files
  37. # cp "$BACKUP_SOURCE_DIR/AddressBook-v22.abcddb" .
  38. sqlite3 "$BACKUP_SOURCE_DIR/AddressBook-v22.abcddb" ".backup AddressBook-v22.abcddb"
  39. cp "$BACKUP_SOURCE_DIR/Configuration.plist" .
  40.  
  41. # folders
  42. cp -r "$BACKUP_SOURCE_DIR/Images" .
  43. cp -r "$BACKUP_SOURCE_DIR/Metadata" .
RAW Paste Data
Top