Backup Linux machine with dd and compress image

2022-10-29

What is dd?

dd (data duplicator) is a command-line utility in Unix and Linux operating systems that is used for copying and converting files. It is a powerful tool that can be used for various purposes, including copying data between devices, creating disk images, and performing low-level operations on data.

Detect partitions for backup

sudo fdisk -l

Backup and compress with 7zip (preferred)

sudo dd if=/dev/nvme0n1p6 bs=32M | 7z a -si -t7z -mx=9 -m0=LZMA2 -mmt6 /media/user/data/backup/system-$(date "+%Y%m%d%H%M%S").img.7z

Restore from backup (7zip)

sudo 7z x -so /media/user/data/backup/system.img.7z | dd of=/dev/nvme0n1p6 bs=32M

Backup and compress with gzip

sudo dd if=/dev/nvme0n1p6 conv=sync,noerror bs=64K | gzip -c -9  > /media/user/data/backup/system-$(date "+%Y%m%d%H%M%S").img.gz

Restore from backup (gzip)

sudo gunzip -c /media/user/data/backup/system.img.gz | dd of=/dev/nvme0n1p6