New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus • Advice and insight from world-class Apple enthusiasts • Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Backup data to CD via the command line


Post Reply New Thread Subscribe

 
Thread Tools
gatorparrots
Guest
 
Posts: n/a

Here is how to create a 100MB drive image, backup data to it, and then burn it onto a CD (directly in the commandline, with only the built-in tools). One possible application: This could be easily modified and incorporated into a script that will backup your Entourage mail databases every week, good for up to six uses (6x100MB) depending on the size of your mail data...

hdiutil create -fs HFS+ -volname Backup -size 100m ~/Desktop/backup.dmg
hdiutil mount ~/Desktop/backup.dmg
ditto -rsrc -V ~/Desktop/datatobackup /Volumes/Backup >> /Volumes/Backup/backup.log
hdiutil unmount /Volumes/Backup
hdiutil burn ~/Desktop/backup.dmg -noverifyburn -noeject


It will prompt you for a disc, insert one and it will burn your disc:
Code:
Please insert a disc: 
Starting
Initializing
Saving temporary image
Opening session
Writing track
............................................................................
Finishing writing
............................................................................
QUOTE Thanks
gatorparrots
Guest
 
Posts: n/a

Here is a script to backup the Entourage mail database to a CD. I have mine as a cron task that runs every Friday before I leave work.
The CD tray opens at the set time as if to say "Feed me"!
Simply insert a CD and off it goes! Ahh, the power of Mac OS X.

Please note that this script requires fileutils to be installed. The -h in du -sh is for Human readable, meaning it will return the results in megabytes.
A pre-compiled binary can be obtained here:
http://homepage.mac.com/rgriff/file.html
or fink install fileutils works for those with using the fink pagackage manager.

Code:
#!/bin/sh
#This script will backup your Entourage mail database to a CD

username="`who | fgrep console | awk '{ print $1 }'`"
if [ "$username" = "" ]; then
    echo "No one logged in via GUI (console)" >&2
    exit 1
fi
userhome="`eval echo ~$username`"date=`date +%Y.%m.%d`
size=`/usr/local/bin/du -sh "/Users/$username/Documents/Microsoft User Data" | awk ' { print $1 } '`

#Quit Entourage and give it time to write its database to disk
/usr/bin/osascript -l AppleScript -e 'tell Application "Microsoft Entourage" to quit'
/bin/sleep 4

/usr/bin/hdiutil create -fs HFS+ -volname Backup-$date -size $size /Users/$username/Desktop/backup.dmg
/usr/bin/hdiutil mount $userhome/Desktop/backup.dmg
/usr/sbin/disktool -r
echo $date >> /Volumes/Backup-$date/backup.log
/usr/bin/ditto -rsrc -V "$userhome/Documents/Microsoft User Data/Office X Identities/Main Identity/" /Volumes/Backup-$date/ >> /Volumes/Backup-$date/backup.log
/usr/bin/hdiutil unmount /Volumes/Backup-$date
/usr/bin/hdiutil burn "$userhome/Desktop/backup.dmg" -noverifyburn -noeject

#Clean up and relaunch Entourage
/bin/rm -f $userhome/Desktop/backup.dmg
/usr/sbin/disktool -r
/usr/bin/osascript -l AppleScript -e 'launch Application "Microsoft Entourage"'
This works very well for those of us with tray-loading drives, as the opening tray is probably sufficient reminder to insert a blank disc.
Those with slot-loading drives should probably add this line before the 'burn' command:
osascript -l AppleScript -e 'tell Application "Finder" to activate & speak "Please insert a blank CD-R disc."'
QUOTE Thanks
Liquidphyre
Guest
 
Posts: n/a

I am trying to write a script my self which is similar to your own however I think I need to understand the disktool functions a little more. like what kind of functions I can preform with it or if you know of some documentation that I can get a hold of it would help greatly
QUOTE Thanks

Post Reply New Thread Subscribe


« radio Buttons | Upgrading PERL Forum Setup, MySQL, etc. »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
DVD R or DVD RW? (Difference?) Joeytpg Switcher Hangout 17 03-24-2010 11:09 AM
Entourage Backup scottatron OS X - Apps and Games 0 02-23-2005 11:43 PM
iPod data backup probs mig.gentry iPod Hardware and Accessories 0 01-22-2005 03:50 PM
PB: data loss with external Firewire harddrive madRAM Apple Notebooks 1 10-17-2004 06:21 PM
Lots of data outgoing and incoming hollerz1 OS X - Operating System 1 06-22-2004 02:53 PM

All times are GMT -4. The time now is 04:46 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?