Linux Backup and Disk Imaging Cheat Sheet

Backup, copy, imaging, clone, and storage troubleshooting workflows on Linux.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Copy and Synchronize

Copy, archive, and sync data efficiently.

Copy a directory tree preserving metadata

Preserve mode, ownership, timestamps, and symlinks.

bashANYcparchivecopy
bash
cp -a /src/. /dst/

Preserve mode, ownership, timestamps, and symlinks.

Mirror a directory with rsync

Powerful local or remote copy preserving metadata and ACLs when supported.

bashANYrsyncarchivecopy
bash
rsync -aHAX --info=progress2 /src/ /dst/

Powerful local or remote copy preserving metadata and ACLs when supported.

Mirror and delete removed files

Make the destination match the source exactly.

bashANYrsyncsyncdelete
bash
rsync -a --delete /src/ /dst/

Make the destination match the source exactly.

Sync a directory over SSH

Efficiently transfer deltas to a remote server.

bashANYrsyncsshbackup
bash
rsync -aP /src/ user@host:/backup/

Efficiently transfer deltas to a remote server.

Create a compressed tar archive

Package and compress a directory tree.

bashANYtarbackuparchive
bash
tar -czf backup.tar.gz /data

Package and compress a directory tree.

Extract a tar archive

Restore archive contents to a target directory.

bashANYtarrestorearchive
bash
tar -xzf backup.tar.gz -C /restore

Restore archive contents to a target directory.

List archive contents

Inspect what an archive contains before extracting.

bashANYtarlistarchive
bash
tar -tf backup.tar.gz

Inspect what an archive contains before extracting.

Create a cpio archive from find

Useful in some initramfs and recovery workflows.

bashANYcpioarchivefind
bash
find . -print | cpio -ov > archive.cpio

Useful in some initramfs and recovery workflows.

Show throughput for a pipeline

Add transfer progress to streaming backup pipelines.

bashANYpvbackupprogress
bash
tar -cf - /data | pv | gzip > backup.tar.gz

Add transfer progress to streaming backup pipelines.

Compute a checksum for a backup

Record integrity hashes for backup artifacts.

bashANYsha256sumbackupintegrity
bash
sha256sum backup.tar.gz > backup.tar.gz.sha256

Record integrity hashes for backup artifacts.

Images and Clones

Create raw images and clone or restore devices.

Create a raw disk image

Image a disk device to a raw file.

bashANYddimagedisk
bash
sudo dd if=/dev/sdb of=disk.img bs=64K status=progress conv=sync,noerror

Image a disk device to a raw file.

Write a raw image back to disk

Restore a disk image onto a target device.

bashANYddrestoredisk
bash
sudo dd if=disk.img of=/dev/sdb bs=64K status=progress conv=fsync

Restore a disk image onto a target device.

Recover an unhealthy disk with ddrescue

Preferred over dd for failing disks because it tracks progress and retries.

bashANYddrescuerecoverydisk
bash
sudo ddrescue -f -n /dev/sdb disk.img disk.log

Preferred over dd for failing disks because it tracks progress and retries.

Backup a GPT partition table

Save GPT headers and partition entries to a file.

bashANYsgdiskgptbackup
bash
sudo sgdisk --backup=gpt.backup /dev/sdb

Save GPT headers and partition entries to a file.

Restore a GPT partition table backup

Restore GPT layout from a saved backup file.

bashANYsgdiskgptrestore
bash
sudo sgdisk --load-backup=gpt.backup /dev/sdb

Restore GPT layout from a saved backup file.

Inspect a virtual disk image

Show image format, virtual size, and backing file info.

bashANYqemu-imgimagevirtual-disk
bash
qemu-img info disk.qcow2

Show image format, virtual size, and backing file info.

Convert a virtual disk image

Convert between raw, qcow2, and other image formats.

bashANYqemu-imgconvertimage
bash
qemu-img convert -O qcow2 disk.raw disk.qcow2

Convert between raw, qcow2, and other image formats.

Compress a raw disk image

Compress large raw images for storage or transfer.

bashANYgzipimagecompress
bash
gzip -1 disk.img

Compress large raw images for storage or transfer.

Compress an image with xz

Use stronger compression for cold storage backups.

bashANYxzimagecompress
bash
xz -T0 disk.img

Use stronger compression for cold storage backups.

Compare two images byte-for-byte

Quick equality check for cloned images of the same size.

bashANYcmpimageverify
bash
cmp disk1.img disk2.img

Quick equality check for cloned images of the same size.

Troubleshooting

Find hot paths, busy mounts, and performance or capacity problems.

Show disk throughput and utilization

Inspect per-device read/write rates and utilization over time.

bashANYiostatperformancedisk
bash
iostat -xz 1

Inspect per-device read/write rates and utilization over time.

Watch per-process I/O usage

Find which processes generate the most disk I/O.

bashANYiotopperformanceio
bash
sudo iotop

Find which processes generate the most disk I/O.

Show per-process I/O counters

Track read/write activity by process over time.

bashANYpidstatperformanceio
bash
pidstat -d 1

Track read/write activity by process over time.

Show system-wide I/O wait and block activity

Quick check for iowait, swap, and block device pressure.

bashANYvmstatperformanceio
bash
vmstat 1

Quick check for iowait, swap, and block device pressure.

Filter kernel logs for storage messages

Look for hardware and filesystem errors in kernel logs.

bashANYdmesgstorageerrors
bash
dmesg | egrep -i 'sd[a-z]|nvme|md|I/O error|ext4|xfs'

Look for hardware and filesystem errors in kernel logs.

Search journal for disk errors

Kernel journal view for storage-related problems.

bashANYjournalctlstorageerrors
bash
journalctl -k | egrep -i 'I/O error|blk_update_request|nvme|md'

Kernel journal view for storage-related problems.

Interactive disk usage explorer

Find large paths interactively with a terminal UI.

bashANYncdudisk-usageinteractive
bash
sudo ncdu /

Find large paths interactively with a terminal UI.

Find large files

Locate unexpectedly large files on a filesystem.

bashANYfindlarge-filesdisk-usage
bash
find /var -xdev -type f -size +1G -printf '%s %p
' | sort -n

Locate unexpectedly large files on a filesystem.

Find deleted files still consuming space

Useful when df is full but du cannot explain it.

bashANYlsofdeleted-filesspace
bash
sudo lsof | grep '(deleted)'

Useful when df is full but du cannot explain it.

Trim mounted SSD filesystems

Discard unused blocks on mounted SSD-backed filesystems.

bashANYfstrimssdtrim
bash
sudo fstrim -av

Discard unused blocks on mounted SSD-backed filesystems.

Recommended next

No recommendations yet.