How to backup your disk with dd: Difference between revisions

From www.ReeltoReel.nl Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
Line 21: Line 21:


  $ sudo dd  if=/home/secteur_boot.dd  of=/dev/hda  bs=512  count=1
  $ sudo dd  if=/home/secteur_boot.dd  of=/dev/hda  bs=512  count=1
=Advanced options=
oflag=direct,sync
for writing to slow devices such as SD cards, oflag=direct keeps it from filling up the process's memory with the backlogged output, and oflag=sync keeps it from filling up the kernel's memory.
direct is a good idea if you want to avoid buffering on the write end, but sync will severely degrade performance if the drive you're writing to does its own buffering. It will force every write to flush the drive's buffer too before moving on.
also: status=progress

Latest revision as of 09:35, 26 June 2021

I had several bad experiences losing my data in my life. Sometimes because of the hardware, sometimes because of my stupidness or inexperience. At least, it learned to be careful. I backup my data regularly, and on several support concerning the important ones.


I sometimes back up my primary partition, where the system is set. If my drive crashed, I want to recover quickly a system without having to reinstall hundreds of applications. I have used several times Partimage and was satisfied. But now I tend to use dd, which basically do the same thing in just one line. The advantage is that it is by default on any Linux distribution.

To back it up on an usb disk :

$ sudo dd   if=/dev/hda1   |   gzip   -v   |   dd   of=/media/usbdisk/backup_hda1.gz

To backup my home and other data partitions, I just copy the files manually, it is faster and there is no need to backup such a thing as the boot sector. But of course you could use the same command above.

When you wish to restore the partition to a new hard drive, just :

$ zcat   /mnt/hdb5/sauvegarde.gz   |   dd   of=/dev/hda1

To do that, you will have probably booted on a live CD Linux as Knoppix to restore the crashed system. In any case, don’t overwrite the system you just booted on !

One tip if you want to back up only the boot sector :

$ sudo dd   if=/dev/hda   of=/home/secteur_boot.dd   bs=512   count=1

And to restore :

$ sudo dd   if=/home/secteur_boot.dd   of=/dev/hda   bs=512   count=1

Advanced options

oflag=direct,sync

for writing to slow devices such as SD cards, oflag=direct keeps it from filling up the process's memory with the backlogged output, and oflag=sync keeps it from filling up the kernel's memory.

direct is a good idea if you want to avoid buffering on the write end, but sync will severely degrade performance if the drive you're writing to does its own buffering. It will force every write to flush the drive's buffer too before moving on.


also: status=progress