I just tried an experiment where I created a loopback filesystem on test.img. First I added files to the mounted filesystem. Then I used gzip to compress is. Then I deleted most of the files and used gzip again. Because the patterns for the deleted files still exist on the image, the file size was the same.
Next I used dd to create a large zeroed out file using up most of the space in the filesystem. Then I deleted the file and tried compressing again. This time the filesize was a lot less. I knew it would help but I wanted to post real results:
Code:
jschiwal@hpamd64:~>ls -lh test* -d
drwxr-xr-x 18 jschiwal users 4.0K 2007-05-31 18:25 test
-rw-r----- 1 jschiwal users 2.4G 2007-05-31 10:35 test1.img.gz
-rw-r----- 1 jschiwal users 2.4G 2007-05-31 17:29 test2.img.gz
-rw-r----- 1 jschiwal users 303M 2007-05-31 18:30 test3.img.gz
-rw-r----- 1 jschiwal users 4.0G 2007-05-31 09:51 test.img
The filesystem is on test.img. Test1.img.gz is using gzip before the deletions. Test2.img.gz is the gzipped filesystem after deletions. Test3.img.gz is the gzipped filesystem after creating the large file of zero's with the command: "dd if=/dev/zero of=zero bs=1024 count=$((1024*512*31)) && rm zero". I based the count on the result of "df test/".
Before zeroing: 2.4G
After zeroing: 303M.
If I had been using a real partition, I would probably have entered the "sync" command to make sure that the cache was emptied. For such a large file, it may not be necessary.
So zeroing out most of the free space this way can dramatically reduce the size of the final backup image file.
If you use dd, you can pipe the output through gzip or bzip2 to reduce the size of the image. Restoring, you can simply use "zcat backup.img | dd of=/dev/hda1" to restore the hda1 device from a gzipped image.
This sites wiki has a page on using dd that includes backing up partitions.
Technically, you could simply redirect the output of zcat to the device. Remember that in Linux "everything is a file". "zcat backup-hda1-May15-2007.img.gz >/dev/hda1"
or
"gunzip -c backup-hda1-May15-2007.img.gz >/dev/hda1"
----
IMHO image backups are useful mainly for new installs, rather than for periodic backups. When recovering from a fatal drive problem, you can use dd using any rescue disk. If you use a large tool such as partimage, you need to make sure you have a live distro or rescue disk that contains the partimage program.
Also, you it would be easy to script the recovery of several partitions using the dd command. So after booting up with an emergency restore rescue disk, you could just start the script to restore the system to the point where you could start using a more sane backup/restore system.