My Backup Scripts

This is a followup to Operation: Simple Functional Backup.

Okay, here are the glorious scripts I came up with.

I call this one dailybackup: [UPDATE: a newer version of my script is posted here]

BASH:
  1. #!/bin/sh
  2.  
  3. SOURCEDIR=/Users/john ;
  4. ARCHIVEROOT=/Volumes/fire/backup ;
  5. ARCHIVENAME=PowerBookHomeDirectory ;rsync \
  6. -a –delete -delete-excluded \
  7. –exclude “/Music/” \
  8. –exclude “/tmp/” \
  9. –exclude “/Library/Caches/” \
  10. –exclude “/Desktop/downloads/” \
  11. $SOURCEDIR/ $ARCHIVEROOT/$ARCHIVENAME ;

I call this one monthlybackup:

BASH:
  1. #!/bin/sh
  2.  
  3. # Comment this out if you want to use the built-in disk burner. If you want to use an external device find it’s name from `hdiutil burn -list`
  4. DEVICE=‘-device IOService:/MacRISC2PE/pci@f4000000/AppleMacRiscPCI/firewire@E/AppleFWOHCI/IOFireWireController/IOFireWireDevice@30e00150abd577/IOFireWireUnit/IOFireWireSBP2Target/IOFireWireSBP2LUN/com_apple_driver_Oxford_Semi_FW911/IOSCSIPeripheralDeviceNub/IOSCSIPeripheralDeviceType05/IODVDServices’ ;
  5.  
  6. # Where the scripts should keep its files while working with them. everything is deleted in the end anyway so /tmp should be suitable.
  7. SCRATCH=/tmp ;
  8.  
  9. # Where dailybackup keeps its archive
  10. ARCHIVEROOT=/Volumes/fire/backup ;
  11.  
  12. # The name of the archive that dailybackup makes.
  13. ARCHIVENAME=PowerBookHomeDirectory ;
  14. # ARCHIVENAME=testtest ;
  15.  
  16. # The size of the chunks that gsplit should make, for DVD or CD.
  17. # I have not experimented with how much overhead there is for each type.
  18. # Please let me know if you have found an optimal size: john AT johnjosephbachir DOT org
  19. MEDIASIZE=4300 ;
  20. #MEDIASIZE=600 ;
  21.  
  22. # stop editing ###########################
  23. cd $ARCHIVEROOT ;
  24. echo “–creating $ARCHIVENAME.tar.gz–” ;
  25. tar czf $SCRATCH/$ARCHIVENAME.tar.gz $ARCHIVENAME ;
  26. cd $SCRATCH ;
  27. echo “–splitting $ARCHIVENAME.tar.gz into $MEDIASIZE MegaByte pieces–” ;
  28. gsplit –numeric-suffixes -b$MEDIASIZE“m” $ARCHIVENAME.tar.gz $ARCHIVENAME.tar.gz_ ;
  29.  
  30. echo “Pieces:”
  31. TOTAL=0 ;
  32. for i in $ARCHIVENAME.tar.gz_* ; do
  33. echo ”   $i” ;
  34. ((TOTAL++)) ;
  35. done;
  36.  
  37. echo “Archive has been split into $TOTAL part(s).” ;
  38.  
  39. echo “–deleting $ARCHIVENAME.tar.gz–” ;
  40. rm $ARCHIVENAME.tar.gz ;
  41.  
  42. COUNTER=0 ;
  43. for i in $ARCHIVENAME.tar.gz_* ; do
  44. ((COUNTER++)) ;
  45. NAME=$ARCHIVENAME.tar.gz_“$COUNTER”_of_“$TOTAL” ;
  46. mkdir $NAME ;
  47. mv$i$NAME ;
  48. echo “–creating disk image of $NAME–” ;
  49. hdiutil create -fs HFS+ -volname $NAME -srcfolder $NAME$NAME”.dmg ;
  50. echo “–deleting $NAME–” ;
  51. rm -r $NAME ;
  52. done;
  53.  
  54. for i in *.dmg ; do
  55. echo “–burning $i–”
  56. hdiutil burn -noverifyburn $DEVICE$i” ;
  57.  echo “–deleting $i–” ;
  58.  rm$i” ;
  59. done;

They could use some further refinement, but for the most part I am happy as a clam.

Two initial questions/problems:

  1. Do any of my geeky readers have recomendations for other things I should exclude in the first script?
  2. split seems to only want to make chunks that are about 600 megabytes each, even though I am specifying 4700 megabytes (DVD size). This is really annoying, but I am assuming that either I am missing something simple, or another solution will present itself.

    update: the problem is the split that ships with OS X seems to have a max size of 2^32 bytes. I installed the gnu coreutils using darwinports (sudo port install coreutils, which installs all the utils as "g__", very nice. If you get the coreutils source from gnu, it builds without a hitch but will install without the "g" prefix), switched to gsplit, and ta-da, everything is working.

1 Response to “My Backup Scripts”


  1. 1 John

    oh my god. i am in heaven.

    $ monthlybackup
    --creating PowerBookHomeDirectory.tar.gz--
    --splitting PowerBookHomeDirectory.tar.gz into 4700 MegaByte pieces--
    Pieces:
    PowerBookHomeDirectory.tar.gz_00
    Archive has been split into 1 part(s).
    --deleting PowerBookHomeDirectory.tar.gz--
    --creating disk image of PowerBookHomeDirectory.tar.gz_1_of_1--
    ...............................................................
    created: /private/tmp/PowerBookHomeDirectory.tar.gz_1_of_1.dmg
    --deleting PowerBookHomeDirectory.tar.gz_1_of_1--
    --burning PowerBookHomeDirectory.tar.gz_1_of_1.dmg--
    Please insert a disc:
    Preparing data for burn
    Opening session
    Opening track
    Writing track
    .....................................................................
    Closing track
    .....................................................................
    Closing session
    .....................................................................
    Finishing burn
    Burn completed successfully
    ......................................................................
    hdiutil: burn: completed

  1. 1 Backup script from Jon Mills at JJB Blog
  2. 2 Backing up my home directory using rdiff-backup at JJB Blog
  3. 3 Split tar archives on the fly at JJB Blog

Leave a Reply




Close
Powered by ShareThis
All of mp3