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]
-
#!/bin/sh
-
-
SOURCEDIR=/Users/john ;
-
ARCHIVEROOT=/Volumes/fire/backup ;
-
ARCHIVENAME=PowerBookHomeDirectory ;rsync \
-
-a –delete -delete-excluded \
-
–exclude “/Music/” \
-
–exclude “/tmp/” \
-
–exclude “/Library/Caches/” \
-
–exclude “/Desktop/downloads/” \
-
$SOURCEDIR/ $ARCHIVEROOT/$ARCHIVENAME ;
I call this one monthlybackup:
-
#!/bin/sh
-
-
# 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`
-
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’ ;
-
-
# Where the scripts should keep its files while working with them. everything is deleted in the end anyway so /tmp should be suitable.
-
SCRATCH=/tmp ;
-
-
# Where dailybackup keeps its archive
-
ARCHIVEROOT=/Volumes/fire/backup ;
-
-
# The name of the archive that dailybackup makes.
-
ARCHIVENAME=PowerBookHomeDirectory ;
-
# ARCHIVENAME=testtest ;
-
-
# The size of the chunks that gsplit should make, for DVD or CD.
-
# I have not experimented with how much overhead there is for each type.
-
# Please let me know if you have found an optimal size: john AT johnjosephbachir DOT org
-
MEDIASIZE=4300 ;
-
#MEDIASIZE=600 ;
-
-
# stop editing ###########################
-
cd $ARCHIVEROOT ;
-
echo “–creating $ARCHIVENAME.tar.gz–” ;
-
tar czf $SCRATCH/$ARCHIVENAME.tar.gz $ARCHIVENAME ;
-
cd $SCRATCH ;
-
echo “–splitting $ARCHIVENAME.tar.gz into $MEDIASIZE MegaByte pieces–” ;
-
gsplit –numeric-suffixes -b$MEDIASIZE“m” $ARCHIVENAME.tar.gz $ARCHIVENAME.tar.gz_ ;
-
-
echo “Pieces:”
-
TOTAL=0 ;
-
for i in $ARCHIVENAME.tar.gz_* ; do
-
echo ” $i” ;
-
((TOTAL++)) ;
-
done;
-
-
echo “Archive has been split into $TOTAL part(s).” ;
-
-
echo “–deleting $ARCHIVENAME.tar.gz–” ;
-
rm $ARCHIVENAME.tar.gz ;
-
-
COUNTER=0 ;
-
for i in $ARCHIVENAME.tar.gz_* ; do
-
((COUNTER++)) ;
-
NAME=$ARCHIVENAME.tar.gz_“$COUNTER”_of_“$TOTAL” ;
-
mkdir $NAME ;
-
mv “$i” $NAME ;
-
echo “–creating disk image of $NAME–” ;
-
hdiutil create -fs HFS+ -volname $NAME -srcfolder $NAME “$NAME”.dmg ;
-
echo “–deleting $NAME–” ;
-
rm -r $NAME ;
-
done;
-
-
for i in *.dmg ; do
-
echo “–burning $i–”
-
hdiutil burn -noverifyburn $DEVICE “$i” ;
-
echo “–deleting $i–” ;
-
rm “$i” ;
-
done;
They could use some further refinement, but for the most part I am happy as a clam.
Two initial questions/problems:
- Do any of my geeky readers have recomendations for other things I should exclude in the first script?
splitseems 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
splitthat 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 togsplit, and ta-da, everything is working.
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