Aug 27, '08 07:30:00AM • Contributed by: zigzogmac
Why save in a DMG?
- To avoid my Mac managing another file system deep tree.
- To simplify moving the backup.
Prerequisites:
For security and convenience, I use ssh transfering protocol with a shared RSA key. If you do not know how to set this up, you should look at that kind of search. Both boxes (the remote and the Mac) need rsync binaries. On the Mac, you'll need a DMG that's as large as the remote system to back up to. Its name and its mounted name are supposed to be the same.
The Script
This script has to be used from your Mac's Terminal.app. Change the variables for your needs. Please be aware that script is not made for direct production use -- there is no error control management code, for instance. It is a raw but usable piece of code to help in backing up.
#!/bin/bash
# Goal : backup my alix box with rsync via ssh in a local dmg file
# The archive and mounted archive name should be the same, w/o .dmg extension for the second
## VARIABLES
# archive Path w/ trailing slash
sauvDMGpath=/Volumes/MactivisteTimed/
# name of the archive, should be the same as the disk, without .dmg
sauvDMGname=nomArchiveDuServeur
# scheme to use below : user@ip_or_host_name
connexionID=RSAUser@IPaddress
# backup root tree, default is "/", all file system
savingPath=/
## MAIN
# mounting image
hdiutil mount $sauvDMGpath$sauvDMGname.dmg
# wait a little bit to assure for FileSystem sync OK
sleep 1
# sync. Ass "z" extension in first extension block when using internet
# or low rated transfert connexion in order to add compression data
rsync -aq -e ssh --delete $connexionID:$savingPath /Volumes/$sauvDMGname/
# unmount image
hdiutil eject /Volumes/$sauvDMGname[robg adds: I haven't tested this one.]
