advertisement

Article:
  The Disaster-Free Upgrade to Mac OS 10.1
Subject:   It's here - now what? No Backup System...
Date:   2001-10-15 07:38:44
From:   sneex
Hi All :-)


Below is an example of how to *really* backup a Mac OS X system. The normal Unix tools which come internal to OSX *do not* work - try them if you don't believe me. They don't work simply because Apple *forgot* to make them HFS+ and MacOS 9 *fork* aware. Which is not a good thing if you still use Mac OS 9x applications...


Based upon the work of others - I just want credit for using their work in a more portable manner (the other methods required that you had more than one HD inside your system - this is somewhat difficult if the system is an OSX Laptop. Hence why I had to modify the standard methods.) :)


HTH;
-Sx- :]


# The method I am using -
# WARNING - You may need to fix formatting errors caused by this posting...


# I am on a G4 laptop, so make sure we
# have mounting points...


/usr/bin/hdiutil eject disk1
/usr/bin/hdiutil eject disk2



# Make a place to backup to...
# Optionally you want to access
# something like a Firewire drv...
/usr/bin/sudo /bin/mkdir /BackUps
/usr/bin/sudo /usr/sbin/chown sneex /BackUps
/usr/bin/hdiutil create -megabytes 1000 /BackUps/backupImage.dmg
/usr/bin/hdid -nomount /BackUps/backupImage.dmg
/usr/bin/sudo /sbin/newfs_hfs -v myBackupDir /dev/disk1
/usr/bin/hdiutil eject disk1
/usr/bin/hdid /BackUps/backupImage.dmg


# You will need hsfpax from the iTools site...
/usr/bin/hfspax -r -w -v -Y -Z /Users/sneex /Volumes/myBackupDir


clear
echo Done...
exit



Notes & Typical Uses (much from the hfspax README doc(s)):


The following examples illustrate some common ways in which you can use hfspax
from a command shell (Terminal). In each command, we include the v option which
makes hfspax's output verbose. If you do not wish to see all the files listed
in detail, omit the v character from the commands given below.


Backing up
To create an archive of the folder thisfolder under the name thisfolder.pax,
type in the command


hfspax -wv -f thisfolder.pax -x cpio thisfolder


If thisfolder is not in the current path, you can either change your working
directory with a command like


cd /Users/Documents/


and then use the above command, or you can use a command like


hfspax -wv -f thisfolder.pax -x cpio /Users/Documents/thisfolder


The effect of these differs significantly when you come to unpack the archive:
if you used cd to change directory, the unpacked archive will be reconstructed
relative to your current working directory. If you used the full path name in
the command as given immediately above, then the old directory will be
completely reconstructed in its original location. It is important that you
appreciate this fundamental difference: when unpacking, hfspax (like pax) will
restore files to the path shown when you list the contents of the archive,
relative to the current working directory (in the command shell).


Listing archive contents
To list the contents of the archive thisfolder.pax, type in the command
hfspax -v -f thisfolder.pax


Restoring
To restore the files contained in the archive thisfolder.pax to their original
locations, type in the command


hfspax -rv -f thisfolder.pax


Note how you can control whether the original directory is reconstructed,
according to how you specify its original path name (see above).


Volume backup
To make a full backup of your active Mac OS X volume, you will need to create a
series of pax archives to cover each of the folders. If you do not have
Mac OS 9.x on the same volume, you can achieve this using the following commands
(which assume that you are creating the archives at the top level of another
volume called backvol):


hfspax -wv -f /Volumes/backvol/Applications.pax -x cpio Applications
hfspax -wv -f /Volumes/backvol/Library.pax -x cpio Library
hfspax -wv -f /Volumes/backvol/Network.pax -x cpio Network
hfspax -wv -f /Volumes/backvol/System.pax -x cpio System
hfspax -wv -f /Volumes/backvol/Users.pax -x cpio Users
hfspax -wv -f /Volumes/backvol/bin.pax -x cpio bin
hfspax -wv -f /Volumes/backvol/private.pax -x cpio private
hfspax -wv -f /Volumes/backvol/sbin.pax -x cpio sbin
hfspax -wv -f /Volumes/backvol/usr.pax -x cpio usr
hfspax -wv -f /Volumes/backvol/mach.pax -x cpio mach*


Note how you access the other volume through its named entry in the /Volumes
path: this is the standard UNIX way of accessing volumes other than the root
(which appears at /). The final command backs up the Mach kernel files, which
remain at the root level of the startup volume. You may also need to run the
following line if you have the developer tools installed:


hfspax -wv -f /Volumes/backvol/Developer.pax -x cpio Developer


You may find it useful to back up the /dev folder. However, this may not be
useful, or it may result in many errors, because of its special nature. If you
do want to try backing it up, use something like:


hfspax -wv -f /Volumes/backvol/dev.pax -x cpio dev


Volume restore
To restore a totally trashed Mac OS X startup volume, restart from another
Mac OS X volume, initialise the disk, and allow the Mac OS X Install CD-ROM to
install OS X 10.x. Then, make sure that hfspax is installed on the
reconstruction disk, restart from it, and simply restore each of the .pax
backups using a command like


hfspax -rv -f /Volumes/backvol/Applications.pax


Note that you have to do this from the disk to which you are restoring, or each
archive will replace the files on the active or 'root' Mac OS X disk. You can
work around this by creating the archives from within each directory, but this
starts to get fairly complex. You can also use this sequence of commands to
create a mirror of your Mac OS X startup volume on another hard disk, although
you will need to recreate some links at the root level.


Moving to a new Mac
When you need to move all your work from one Mac to another, the easiest thing
to do is a full backup (see above) onto an external disk, such as a FireWire
hard disk. Put all the pax files there, and move the disk over to your new
Mac. You will then want to select which files you want to install: a simple way
of doing this is to cd to your Documents folder


cd ~/Documents


and then unpack each archive in turn into that location, using commands
of the form


sudo hfspax -rv -f /Volumes/backvol/Applications.pax


(Note the use of sudo, see below.) You can then change the owner of folders
as necessary, using something like


sudo chown -R mynewusername Applications


as appropriate. Then using the Finder (recall that command line cp will not
preserve resource forks), drag the applications, folders, etc. into their
new locations .


Working incrementally
You can use hfspax's command options to perform incremental backups and restore
incrementally. To create an archive with just files modified since
year 2001 month 08 date 10 hour 07 minutes 30, use


hfspax -wv -f archive.pax -x cpio -T 0108100730/m foldertoarchive


When you want to append those same files to the existing archive called
archive.pax, use the -a option thus:


hfspax -wv -a -f archive.pax -x cpio -T 0108100730/m foldertoarchive


You can also use the -T option with a date given in the above format
(yymmddhhmm, for details see the man page) to select those files to
unpack with hfspax -r. If you want to unpack files into existing folders,
then you should use the -k option, or hfspax will happily trash the existing
files for you, and replace them with those it unpacks. You can combine the
-k and -T (and other options) to produce quite powerful and selective commands,
such as


hfspax -rv -f archive.pax -k -T 0108100730/m


which will unpack only those files modified after the given date from
archive.pax, into the current working folder, but will not over-write
existing files.


sudo or su
Mac OS X has many features of Unix, including strict limitations on privileges
for users. Depending on whether the current user has admin powers, and the
permissions set for folders and files, you may need to assume additional powers
as a 'super user' before you can read or write them. Thus, you may find that you
need to preface any or all of the above commands with the sudo command. You can
also become the super-user ('root') with the su command. You should be extremely
cautious about doing so, because you can rapidly cause all sorts of problems and
damage unless you really really know what you are doing. If you do not know
how to use sudo, then you should read the relevant section of a good Unix guide,
and its man pages (man sudo).


File naming: an important issue
Mac OS X using an HFS+ volume has to cope with both Mac OS 9 and Unix file naming
conventions. When an operating system refers to a file using its full path name
(as hfspax has to do), it uses a separator character between each element in the
full path name. For instance,


/Users/me/Documents/test.rtf


specifies the file test.rtf in the path /Users/me/Documents. Unix uses the '/'
character as its separator, whilst Mac OS 9 uses the ':' character, e.g.


HacHardDisk:Users:me:Documents:test.rtf


If you create or keep files that include a separator in their name, this will
confuse tools such as pax, as the name will be seen to contain part of the
pathname as well. In OS X, this can happen if you use '/' or ':' characters
in file names. This will cause hfspax to break, and its behaviour will then
be unpredictable, and it will corrupt files. Currently, we do not know of a
workaround to help this unfortunate situation.