I've put together a little backup shell script. I wanted to post it and get some comments/suggestions. I'm new to Mac and BSD so it was through a lot of trial and error.
I had the following requirements...
- I wanted the backup data compressed.
- I wanted to preserve the resource forks and such.
- I wanted it to backup various directories some in the gigabytes quickly.
- I wanted it to copy the files over my home network to a Windows server relegated to the lowly job of a file share.
I ended up using hdiutil and mount_smbfs. A lot of sample backup scripts I found create a DMG volume, then use ditto, then compress the dmg, etc. Why can't you just use hdiutil with the -srcfolder option? Does this work different or wasn't available earlier?
Here is my actual backup script, this takes a folder and creates a compressed HFS+ DMG file. In this case it places it in my home directory in a folder called dmgBackup. The 1st command line parameter is a short descriptive name like "iTunes" and the 2nd parameter is the folder path.
BackupFolder.sh:
Then I use this script as a "driver" script to create dmg's of my important directories as well as copy them to the window's box...
Anyway it seems to work ok. Any ideas or comments? Is this a good way to backup files?
I had the following requirements...
- I wanted the backup data compressed.
- I wanted to preserve the resource forks and such.
- I wanted it to backup various directories some in the gigabytes quickly.
- I wanted it to copy the files over my home network to a Windows server relegated to the lowly job of a file share.
I ended up using hdiutil and mount_smbfs. A lot of sample backup scripts I found create a DMG volume, then use ditto, then compress the dmg, etc. Why can't you just use hdiutil with the -srcfolder option? Does this work different or wasn't available earlier?
Here is my actual backup script, this takes a folder and creates a compressed HFS+ DMG file. In this case it places it in my home directory in a folder called dmgBackup. The 1st command line parameter is a short descriptive name like "iTunes" and the 2nd parameter is the folder path.
BackupFolder.sh:
Code:
dmgpath="/Users/Brian/dmgBackup"
shortname=$1
backuppath=$2
echo Starting Backup...
size=`du -sh "$backuppath" | awk ' { print $1 } '`
date=`date +%Y.%m.%d`
ECHO $backuppath - $size of data to backup...
hdiutil create -fs HFS+ -format UDZO -volname $shortname-$date -srcfolder "$backuppath" "$dmgpath/$shortname-$date.dmg"
Then I use this script as a "driver" script to create dmg's of my important directories as well as copy them to the window's box...
Code:
#!/bin/sh
# Run DMG Backups...
# I backup other directories but i kept it short for this example.
/Users/Brian/dmgBackup/BackupFolder.sh iTunes "/Users/Shared/iTunes"
/Users/Brian/dmgBackup/BackupFolder.sh SharedDocs "/Users/Shared/Shared Documents"
# Copy Over Network...
# change User : passcode as necessary
echo Mounting 192.168.0.5/Backup...
mount_smbfs //user:code@192.168.0.5/BACKUP /private/var/automount/Network/WINXP/BACKUP
echo Copy new DMG files...
cp /Users/Brian/dmgBackup/*.dmg /private/var/automount/Network/WINXP/BACKUP
echo Unmounting 192.168.0.5...
umount /private/var/automount/Network/WINXP/BACKUP
echo Cleanup local drive...
rm /Users/Brian/dmgBackup/*.dmg
echo Done.
Anyway it seems to work ok. Any ideas or comments? Is this a good way to backup files?