There is the built in Time Machine that will backup your entire system as it runs and keep backing up files as change.
There are also many 3rd party applications that will run as a full backup and incremental of the entire system while it is mounted and running.
None of these were options that I wanted to follow.
Time Machine is great except for the fact that you cant easily restore from it to another computer in case of a hardware failure.
The other applications are great as well but most of them cost a lot of money and still don't give you what I wanted; a DMG file of my system hard drive.
In the past, they way I have cloned a full system was to restart the Mac form either the MacOS X DVD or a "Tech Drive" with a bootable OS on it. Then fire up Disk Utility and make a DMG image of the hard drive.
This worked great. All for the problem that I have to restart the Mac and its all hands on.
On a server the option to shut it down is now there. Let alone the fact that many of the G5 xserves out there ware headless which make it even harder to reboot and image the system drive.
So I had to come up with a way to make a full bootable copy of a live running system. And I wanted this all automated.
I discovered the Apple System Restore command: asr
ASR can copy a complete running system to another hard drive or existing DMG image.
The downside is that ASR needs and existing DMG and it must be an expandable sparseimage. Sparseimages are not restorable and they take up alot of space.
I wanted a read-only, compressed disk image.
Here is what I came up with:
1. Create a sparseimage file large enough to to clone the hard drive.
2. Name the sparseimage with the date and name of the server.
3. Mount the sparseimage and create a new compressed read-only DMG from the mounted sparseimage.
4. Delete the sparseimage keeping the compressed DMG image at half the size.
If I ever need to restore the system or clone its state to another Mac, I only need to use Disk Utility to restore the DMG to a Hard Drive.
Below is my sample shell script that I will be refining as time goes on.
I named this script: asrclone.sh
It takes two arguments, source hard drive and destination folder.
I type the command then use the drag and drop method the fill in the paths.
Syntax:
asrclone.sh [Source Path] [Destination Path]
Example:
$ ./asrclone.sh /Volumes/HardDrive /Volumes/Backup/Server1
File Contents:
#!/bin/bash
# get date
echo "The create date is: `(set \`date\`; echo $2-$3)`"
echo Building run script
# Create new sparse image with date in name using second arg for destination
echo hdiutil create -size 50g -type SPARSE -fs HFS+J "$2/server1-`(set \`date\`;echo $2-$3)`.sparseimage" > output.txt
# Attach image
echo hdiutil attach "$2/server1-`(set \`date\`;echo $2-$3)`.sparseimage" >> output.txt
# Run ASR to clone drive as first arg to now mounted untiled sparseimage drive
echo sudo asr restore --source "$1" --target /Volumes/untitled/ --erase --noprompt >> output.txt
# Create readonly compressed image for backup compression
echo sudo hdiutil create -format UDZO -srcfolder \"$1\ 1\" "$2/server1-`(set \`date\`;echo $2-$3)`.dmg" >> output.txt
# Unmount the sparseimage and remove it
echo hdiutil detach \"$1\ 1\" >> output.txt
echo rm "$2/server1-`(set \`date\`;echo $2-$3)`.sparseimage" >> output.txt
cp output.txt run.sh
chmod +x run.sh
echo Executing run script
./run.sh
echo removing text files
rm output.txt
echo removing run script
rm run.sh