Can I use dd to back up a mounted partition?

I usually use a live usb to back up a partition using dd (typically sda2). Can I do this while actually in my system ?

I am new to linux but wont the partition be mounted (the partition I am backing up is mounted on root)

sudo dd bs=64K if=/dev/sda2 | gzip > /mnt/backup/backup_sda2_020420_1.img.gz 

many thanks


Solution 1:

You can use dd on a mounted partition but it won't be a good idea for a backup, and less if it is mounted at the root of the filesystem. As far as I know:

  • dd is a low level tool that will copy the full partition byte-by-byte, including all "empty" space with no files, which may actually contain random or old data (in a HDD). For instance, a dd image of a 240 GB partition will be 240 GB in size, even is the partition has 200 GB of free space. You may get some compression with gzip but it may not work well enough.
  • If the filesystem is being used while dd is running on the mounted partition, the image may end up in an inconsistent state with some corrupted files.

For backup, you'd be better with using rsync or some other file-copying or file-syncing tool.