Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to back up files to a single ISO image UNIX
I bring my iBook everywhere, and I store on its drive 80% of my important data, since I use it for studying, working, scripting, doing projects for university, listening to music, downloading stuff, browsing, printing nice articles found on the Web to PDFs, etc. Scared by the fact that hard drives fail when you least expect it -- and trust me, they still fail if you (like me) love your hardware more than your girlfriend. So I spent some days thinking about and coding a little script-based backup system with the following features:
  • low memory usage
  • fast!
  • capable of backing up several directories in a single .iso image, ready to be burned.
My files-to-backup and my backup files must be stored on the same hard disk (the 40GB one inside my iBook), at least until I burn them on CDs every weekend. So, to prevent useless duplicates floating in my laptop, and my confusion during my several daily Spotlight searches, I chose to back up to a disc image (i.e. a single explorable file), instead of a "normal" method of back up (with duplicate files/folders, usually on another drive).

I chose the ISO format instead of a disk image, because the first one is a more standard kind of disc image compared to the second one. It can be mounted and explored or burned on both Mac and on Windows machines (using the nice freeware tool called Daemon Tools, for example). Why did I code a script instead of using one of the tons of backup apps out there? Because the ones I tested don't do exactly what I need, and because doing the things I need myself and watching them work wonderfully makes me happy like a child who has finally received its most-wanted toy from Santa Claus! And by the way, scripting on Mac OS X is so easy that you can't really stop doing it once you get started.

Pre-requisites to run the script:

My script uses the great commandline utility called mkisofs that for Mac OS X is only distributed as source files, at least officially (on the website of the Author). But if you ignore what words like "source file" or "compile" mean, or if you (like me) can't or don't want to install the 1GB+ of XCode just for compiling the sources of mkisofs (that is a few KB utility), you can get the binary distribution in four easy steps:
  1. Download and mount the DMG image of the freeware software called DVD Imager.
  2. When it appears on the desktop, open it, control-click on the DVD Imager application, pick Show Package Contents from the pop-up menu, and navigate to Contents -> Resources.
  3. Copy mkisofs to your /bin folder using the Terminal and a command like the following: sudo mv /Users/eldino/Downloads/mkisofs /bin/. You need Admin priviliges to do this, so you have to logout from your daily-use limited account (you don't work daily as Admin user, right?) and log in as Admin (or ask the Admin of your machine to do it for you) to accomplish that mv job.
After you do all this, type mkisofs -h: if all has gone well, you have succesfully placed mkisofs in your system binaries folder, and so it should be available from every path (exactly like mv, cp, uptime, etc.).

How the bashbackup script works:
  1. It creates a destination folder (ex. /Users/YourName/Backup).
  2. It creates a temp subfolder in the destination folder named following this scheme Backup_todaydate (ex. /Users » YourName » Backup » Backup_2007-12-30).
  3. It copies all your files and folders to back up to the temp subfolder.
  4. It creates a textual index of the content of your temp subfolder (i.e. Backup_2007-12-30_index.txt) in the destination folder (thanks to the author of this hint for the inspiration!).
  5. It creates the ISO disc image of the temp subfolder (i.e. Backup_2007-12-30.iso).
  6. It deletes the temp subfolder.
How to install the script:
  1. Download it (1.5KB) and expand the archive.
  2. Copy eldino's_bashbackup.sh to a folder of your choice.
  3. Fire up Terminal, go to the folder where you saved the script and type chmod 755 eldino's_bashbackup.sh then press Enter.
Congrats! The script is now installed and executable!

Obviously, you can easily customize every key aspect of the script, like changing the destination folder or the ISO image naming scheme, adding/removing folders to the folders to back up list etc. For the script-editing part, I personally use the freeware developer-oriented text editor called Smultron, that colour your syntax and open multiple files in the same sidebar, but of course any other textual editor would be fine. To get the file paths of your folders to back up in a simple way, I suggest you to get the nice contextual menu plugin called FilePathCM; it's free and works great!

How to use the script:

I suggest you to run this script at least weekly, using a cron job. Then you can burn several ISO images on a single 700MB/4.3GB disc, or you can burn one image per disc. I personally like to burn seven or eight ISO images on one CD-R, because the personal data I back up don't take so much space (my ISO images are about 90MB to 100MB each). You can also call my script from inside an Automator workflow or an AppleScript, or use it with the nice app DoSomethingWhen (that permits you to, for example, run the script when you plug in your external drive). The possibilities are endless!

The possible usages of the textual index file include:
  • If the text indexes reside on a volume indexed by Spotlight, you might be able to figure out in what image or images a specified file is placed in just typing its name or part of its name into the Spotlight search field.
  • If the text indexes resides on a read-only media, like a CD/DVD, you can load them into a text editor and do a search for the file you need: if the search is positive, then you can mount the disc image, otherwise you can go forward with the next disc.
Possible variants:
  • Instead of creating an ISO image, you could create a single zip (or gzip, tar, or bz2) file, but you will lose the capacity (at least using the native Mac OS X tools) to explore the result without first expanding it.
  • Instead of burning backup images on CD/DVDs, you could save them on an external drive and keep them there until the next Ice Age.
As usual, for questions, problems, suggests, insults, congrats or whatever else, don't hesitate to write me an email or post a comment.
    •    
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[30,755 views]  

A script to back up files to a single ISO image | 9 comments | Create New Account
Click here to return to the 'A script to back up files to a single ISO image' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to back up files to a single ISO image
Authored by: CBrachyrhynchos on Mar 28, '07 08:54:21AM

hdiutil on OS X 10.4 will do the same thing as mkisofs here.

hdiutil -o $destinationFolder/Backup_$(date "+20%y-%m-%d").iso $destinationFolder/$destinationSubfolder



[ Reply to This | # ]
A script to back up files to a single ISO image
Authored by: jsenn on Mar 30, '07 11:12:36AM
I think you mean something like this:
hdiutil makehybrid -o dst-iso-image.iso src-files-here -hfs -iso -joliet
Also there used to be problems with hdiutil and images >2GB (not sure whether this is still an issue)

[ Reply to This | # ]
girlfriend
Authored by: snoozer on Mar 28, '07 11:03:41AM

Do you love your hardware more than you love your girlfriend, or do you love your hardware more than your girlfriend loves your hardware?

I think I know the answer, but I thought I'd give you an out in case your girlfriend reads this. :)



[ Reply to This | # ]
girlfriend
Authored by: doneitner on Mar 28, '07 06:15:39PM

I also had to read it twice and still wasn't sure which way he meant. :)

As long as we're on the subject of backing up to ISOs, would anyone be interested in taking my old (Rexx) script which can backup to as many (or rather as few) ISO images as needed to store any number of files? It's the one thing I think it really missing in Burn Folders -- the ability to drop any amount of files of any size and back them up (cleanly) to CDs/DVDs without using some proprietary "archive format".



[ Reply to This | # ]
Why copy
Authored by: dumas on Mar 28, '07 11:58:54AM

Why make the copy, make the iso from that, and then delete the copy? Just make the iso from the files directly and save steps and temporary disk space.



[ Reply to This | # ]
mkisofs available from fink
Authored by: macubergeek on Mar 29, '07 02:38:28AM
mkisofs is also available via fink
http://www.finkproject.org/
do
fink install mkisofs

[ Reply to This | # ]
A script to back up files to a single ISO image
Authored by: lras on Mar 29, '07 06:34:15AM
Looks like there is a small bug in your script. It prevents the temporary backup dirs from being removed.
On line 52, you cd $destinationFolder/$destinationSubfolder, and on line 59, you rm -R -f $destinationFolder/$destinationSubfolder, without having moved back up again. You don't get any error messages because of the -f option.

[ Reply to This | # ]
A script to back up files to a single ISO image
Authored by: rflorence on Mar 29, '07 08:35:12AM

Cp is not a great utility to use in a backup scheme. As used in this script it will not preserve resource forks, attributes, or even the creation/modification/access times of the files. There are many utilities available on MacOS that with the appropriate options do proper backups, including ditto, tar, rsync, and disk utility. Tar and rsync also do incremental backups, which can save time.

- Ronald Florence



[ Reply to This | # ]
A script to back up files to a single ISO image
Authored by: osxpounder on Mar 29, '07 11:44:12AM

Since you're using an ISO disk, and not an HFS+ one ... are all the files truly backed up, intact, including metadata? Is there a file size limit? Is this completely compatible with the file system on the Mac?



[ Reply to This | # ]