backup - In linux, how do I create/restore an image snapshot of my entire drive?

20
2014-04
  • user35997

    I'm too spoiled by Windows utilities that take a digital snapshot of your entire drive, which you can then restore from in the event of a drive crash. (e.g. like Time Machine for Mac OS X).

    Is there a similar way of doing this in Linux?

  • Answers
  • Norman Ramsey

    The tool you want (which most closely resembles Time Machine) is called rsnapshot. Unlike normal backup tools it copies only things that have changed, and it allows you easily to travel to many points in time. You can tell it how much disk space it is allowed to have, and it adjusts the number of snapshots kept to stay within that limit. A very nice tool.

  • StuffMaster

    PartImage runs from the command line or as a text GUI. It has one important advantage over dd:

    Partimage will only copy data from the used portions of the partition. For speed and efficiency, free blocks are not written to the image file. This is unlike the 'dd' command, which also copies empty blocks.

  • Charlie Martin

    You can simply do "dd if=/dev/sda of=/path/to/target/backup" if you know you have the room where you are trying to put it. You could also do "dd if=/dev/sda | bzip2 > /path/to/target/backup" to compress on-the-fly. This might take some time though.

    Or, you could do "tar --preserve-permissions -cjf backup.tar.bz2 /what/to/backup" as a user that has all the neccessary read permissions. Take your pick.

    Addendum: I recently bought a new laptop, preinstalled with Vista. I figured I wanted to preserve vista somewhere, in case I wanted to try it out at some point, so the first time I booted the computer (with a linux livecd), I did this:

    dd if=/dev/sda | ssh 10.0.0.1 "bzip2 > ~/vistadrive.bz2"
    

    This was on a fast local network, of course. Otherwise it would have been more prudent to compress before transmission:

    dd if=/dev/sda | bzip2 | ssh 10.0.0.1 "cat > ~/vistadrive.bz2"
    

    Hope you find some of this useful.

    Edit: Oops. Changed bb to dd...

  • Michael Trausch

    I use a two-fold strategy: #1 is LVM snapshots and number two is rsnapshot, which I use to make point-in-time backups to a dedicated external hard disk drive. The external hard disk drive is placed so that I can easily yank it on my way out the door should something bad happen. I don't (yet) use an off-site mechanism other than periodically burning a snapshot to a series of encrypted DVD discs and shipping them to a friend's place in another city for storage.

    I highly recommend rsnapshot because of the way it does the snapshots, using hard links for things that haven't changed. If your home directory goes bonkers, you can just take an rsnapshot copy and tarpipe or rsync it back to your new home partition after reinstalling or recovering from drive failure.

  • deepwell

    I always worried about using dd when the drives were differently sized. Or had different numbers of heads/sectors/tracks/etc.

    dd is very useful when snapshotting and reflashing the same drive. Especially USB drives or windows partitions. But when going from a 500Meg to a 1500Meg drive, I get concerned.

    Besides, when my drive fails, I like to be able to use it as an excuse to upgrade to a newer OS.


    All that said, good old tar does a nice job! GNU-tar includes diff-tar-against-files, only-update-files-that-have-changed, and only-archive-files-newer-than-date options.

    (I should mention: I did run into a bug a few years back that required me to download and install a newer version of GNU-tar. (Something to do with very long pathnames and multiple volumes.) No big deal. Just be aware that's always an option.)

    You should probably exclude /proc, /sys, and perhaps /var/log/lastlog or /mnt. (I usually back up to an external drive mounted under /mnt. Backing up the backup -- not so good!)

    Including /dev can be worthwhile. gnu-tar will handle devices properly (mknod). Though you probably won't use the backed up /dev during a restore. (Occasionally its nice to see what permissions or links you had set up before.)

    Also, you might want to dump fdisk & rpm info before backing up. E.g.

    /sbin/sfdisk -l /dev/sda > /....../info_sda
    rpm -qa | sort > /...../info_rpms
    rpm -qa --qf "%{ARCH} \t %{NAME}-%{VERSION}-%{RELEASE}\n" | sort -k2,2 > /........./info_rpms_arch
    

    As well as mounting any "optional" user-mounted filesystems.

  • Evan

    You can have snapshots on Linux using LVM, the logical volume manager.


  • Related Question

    windows 7 - Restore/Imaging On Different Physical Machines
  • RobDude

    I've used a couple of disk-imaging tools in the past; but they always required the hardware on the machine be identical to the one that created the image. Is this still the case?

    I have a work-related PC that requires a fair amount of specialized applications to be installed and configured. I'm getting a new PC and wondering if I could create an 'image' of the old one and install it on the new.


  • Related Answers
  • Dave M

    We use Symantec Backup Exec System Recovery for this. We also have a great deal of specialized software that takes a lot of time to install. Save a great deal of time and really handy if the system fails. Just took an image from an approximately one year old laptop and restored to a four year old model. A few driver fixes and we were ready to go.
    There is an eval on their site Symantec BESR