Drive Backup Over SSH With GZip Compression
If you’ve worked hard to configure your Linux machine and can’t afford to lose it, try creating an image of it using dd
periodically.
It wouldn’t make much sense to store the image of the drive on the drive itself, but luckily dd
is smart and you can combine it with ssh
and gzip
to store your stuff off-site.
# dd if=/dev/sda | ssh user@backup.remotehost.com dd of=/backup/drive.img.gz
At this point the drive.img.gz
file is quite large. If you’re going over the internet this will take a really long time and kill your bandwidth.
Try this:
# dd if=/dev/sda | gzip | ssh user@backup.remotehost.com dd of=/backup/drive.img.gz
Notice the gzip
pipe right before the ssh
command compressing the stream before it gets sent to backup.remotehost.com
. You can also tell dd
to create an image of a specific partition only (specify /dev/sda2
as the input stream)
To restore a drive image, log into backup.remotehost.com
and type:
# dd if=/backup/drive.img.gz | gzip -d | ssh root@livecd.host dd of=/dev/sda
You should only restore to a drive that is not in use (possibly an OS running off of a Live CD?).
I was able to reduce my drive.img.gz
by almost 75% using gzip! You may find other compression tools to be better or worse depending on the data you are imaging.