2

From what I've read, you can back up an entire partition like this:

dd if=/dev/sda1 of=/media/external/backup

Can anyone tell me if I need to worry about files being changed while doing this? Could it be that some critical system file might get changed during the dd operation and then when you want to restore the backup, it won't work?

I'm on Ubuntu 12.04.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Magnus
  • 1,413
  • Generally the device you want to backup should be unmounted before further processing since it is possibly that not everything in the buffer is written to the storage medium. To reduce the risk of a corrupted backup you can run sync before but it is not advisable. – user1146332 Sep 17 '12 at 14:28
  • Is it possible to unmount /dev/sda1 even if it is the partition where Linux is installed? – Magnus Sep 17 '12 at 14:30
  • The usual way to backup the root partition is to boot from another partition or another medium (rescue disc, usb stick, tape, etc.) and start the backup from there. I recommend further to take a look at fsarchiver. It's a file based backup tool and you can restore the backup on another partition that is at least equally sized. dd in contrast is sector based and you can restore the data only on partitions that equals the source partition of the backup (equal amount of sectors). – user1146332 Sep 17 '12 at 14:36

1 Answers1

2

Unfortunately this may not be safe when filesystem you are backing up like this is mounted. Consider such situation:

  • Your backup is half way done (i.e. first half of partition is already written to backup file.

  • Now you (or some program) make a copy of a file that happens to be located on the other half of partition. Filesystem knows nothing about you backup process but it decides that there is some space left at the beginning of partition and this is where your copy of file is made. Obviosly, your backup won't contain this file.

  • Now since you think you have a copy of this file, you decide you don't need original file and deletes it. And right after that, your backup process comes to the place where this file was and write information to the backup file that this file was deleted.

As you might expect, you end up without any copy of this file in your backup. That's just an example and it isn't worst thing that could happen.