Backup Linux machine with dd and compress image


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