Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to backup a running Debian system to some kind of image file, that could simply be written back to another hard disk using dd in case of failures of the original (backed up) Debian system?

I am especially looking for a tool directly available in the repositories, as I have Debian Wheezy running on a raspberry pi and therefore, I need support for the ARM architecture, which is given quite reliable for packages of the Debian repositories.

share|improve this question
I wouldn't recommend trying to get a block-for-block copy from rw-mounted filesystem. Smallest write can corrupt it and you think you have a workable backup. So mount -o remount,ro the drive you are copying if you opt for dd,dump or similar. Copying withing filesystem with rsync or any other method including cp is safe for live system. – WhimsicalWombat May 21 '15 at 2:38

dd is good if you don't mind generating an image file that's exactly the size of your raw disk. rsync is good if you want easy file-level access. But the standard means of backing up a filesystem is dump and restore (aptitude install dump).

For a device like the Raspberry Pi, I'd back up as follows, assuming an MS-DOS partition table and that the disk is /dev/sda:

  • dd if=/dev/sda of=sda-boot-sectors.img count=2048 to get an image of the boot section of the disk.
  • fdisk -lu /dev/sda >sda-partition-table.txt for later human reference.
  • dump -0af sda1-root-level0.dump /dev/sda1 and repeat for each partition you want to back up.

You can then compress the lot and leave it somewhere safe. To restore, you'd use dd to restore the partition table and boot sectors, reload the partition table, make the new filesystem(s), and use cd /mnt/new-filesystem; restore -rf /some-location/sda1-root-level0.dump.

The upsides:

  • dump gets a complete copy of the filesystem, including ACLs, extended attributes, ownership, sparse files, special filesystem attributes — everything is dumped as-is.
  • It'll only copy the blocks you need, ignoring unused ones.
  • It's standard unix tool and readable by a lot of other unix tools.

The downsides:

  • it will produce corrupted snapshots if the file system is written to during the dump
  • it's more difficult to mount the backed up image (which you can do with disk images) or get to individual files (which you can get with rsync backups).
  • It's filesystem type-specific. You can dump an ext3 filesystem and restore it in an ext4 one, but you can'd dump any type of filesystem. Most mature filesystems have their ownd dump versions. The standard Debian dump does ext2, ext3 and ext4. If you use a Flash-specific filesystem, your options may be different.
share|improve this answer
It's not stated in the manpage for dump that the filesystem shouldn't be written to. I mean, this sounds like a sensible restriction, but it's a pity that it's not mentioned in the manpage, so that someone may make this error... – imz -- Ivan Zakharyaschev Sep 24 '15 at 14:28
Thanks to your post, I have learned about this tool (dump/restore). I'm going to use it to make a copy of a filesystem with something like: mkfs.ext4 /dev/sda1; mount /dev/sda1 /mnt/disk; cd /mnt/disk; dump -0af - /dev/sda5 | restore -rf - – imz -- Ivan Zakharyaschev Sep 24 '15 at 15:55

Use dd for the boot-sector and rsync -aHS for the files. You have to exclude "virtual" filesystems like /proc /sys and any RAM-disks (tmpfs).

If you want to keep the partitioning as well, you can dump that with sfdisk or recreate it with parted.

share|improve this answer
Thanks, sounds very interesting, did you already tset this in the past? How do I create a complete image out of these parts, just use a loopkack device? (Yes, want to keep partitioning and so on. Want an image ready to be written to a new SD card / disk without further fiddling) – stefan.at.wpf Jun 22 '12 at 23:10
@stefan.at.wpf I just mixed up some of my solutions for cloning VMs, creating physical servers (autoyast/kistart) making a raid1-mirror out of a non-mirrored system and the usual way to replicate (static) parts of the filesystem for cluster nodes. I do not use this myselv. My method would be to autoinstall new server (including a backup-client) and then restore via backup the contents of the old server to the new server. – Nils Jun 23 '12 at 21:16

For Debian, you really only need to back up your data and configuration files.

To back up existing state:

  • Back up package selections with dpkg --get-selections > dpkg_selections.
  • Back up the debconf database with sudo debconf-get-selections > debconf_selections.

To apply this to a new system:

  • First apply debconf selections with sudo debconf-set-selections < debconf_selections.
  • Apply package selections with dpkg --set-selections < dpkg_selections.
  • Install packages with apt-get dselect-upgrade.

Your data should primarily be in /home and /var (e.g., /var/lib/mysql for MySQL, /var/www for Apache, etc.). You should be able to figure out which applications are important to you.

Configuration will be primarily in /etc. Again, it shouldn't be difficult to pick out what's important for you.

share|improve this answer
To get debconf-get-selection run apt-get install debconf-utils – pandita Aug 11 '15 at 12:06

I have tried so much backup and restore software and was never happy. This is what I do now: I have a second Debian installed on a spare computer (same MB, NIC card, etc). Every evening I rsync from machine A to machine B. There are some files that I hold back (/etc/network/interfaces, /etc/hosts, /etc/hostname) since I don't want conflicts of the two running systems. Actually, I do have copies of them in another folder. I also disable some services that I don't need to run on machine B (postfix, mysql, etc). I have a script written on machine B that will basically turn it into machine A (replace those files that I held back), restart the NIC and enable the services that were disabled. Of course machine A needs to be off when I run the script or there will be havoc. I test machine B monthly by turning off machine A, running the script, and doing some tests to make sure it is up to date and running properly. It works like a charm!

share|improve this answer

Check out Clonezilla. I see it listed in the standard Debian repos. http://clonezilla.org/

Edit: Probably not, Clonezilla list requirements on their front page: "X86 or x86-64 processor"

share|improve this answer
Interesting project though, thank you anyway :-) – stefan.at.wpf Jun 22 '12 at 23:11

I don't know, if this is good to do, when the system is running, but this is what I do.

sudo dd if=/dev/mmcblk0 of=/path/to/backup/directory/backup.img bs=1M

as I said, maybe there is a better solution, in that case I would like to know it as well!

share|improve this answer

To back up my pi, I remove the microSD card, and plug it into my laptop. Then run a dd to produce a file on my laptop of the entire disk, as per above:

dd if=/dev/mmcblk0 of=/path/to/backup/directory/backup.img bs=1M
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.