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 a directory tree preserving metadata
cp -a /src/. /dst/

# Preserve mode, ownership, timestamps, and symlinks.

Mirror a directory with rsync
rsync -aHAX --info=progress2 /src/ /dst/

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

Mirror and delete removed files
rsync -a --delete /src/ /dst/

# Make the destination match the source exactly.

Sync a directory over SSH
rsync -aP /src/ user@host:/backup/

# Efficiently transfer deltas to a remote server.

Create a compressed tar archive
tar -czf backup.tar.gz /data

# Package and compress a directory tree.

Extract a tar archive
tar -xzf backup.tar.gz -C /restore

# Restore archive contents to a target directory.

List archive contents
tar -tf backup.tar.gz

# Inspect what an archive contains before extracting.

Create a cpio archive from find
find . -print | cpio -ov > archive.cpio

# Useful in some initramfs and recovery workflows.

Show throughput for a pipeline
tar -cf - /data | pv | gzip > backup.tar.gz

# Add transfer progress to streaming backup pipelines.

Compute a checksum for a backup
sha256sum backup.tar.gz > backup.tar.gz.sha256

# Record integrity hashes for backup artifacts.

## Images and Clones
Create a raw disk image
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
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
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
sudo sgdisk --backup=gpt.backup /dev/sdb

# Save GPT headers and partition entries to a file.

Restore a GPT partition table backup
sudo sgdisk --load-backup=gpt.backup /dev/sdb

# Restore GPT layout from a saved backup file.

Inspect a virtual disk image
qemu-img info disk.qcow2

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

Convert a virtual disk image
qemu-img convert -O qcow2 disk.raw disk.qcow2

# Convert between raw, qcow2, and other image formats.

Compress a raw disk image
gzip -1 disk.img

# Compress large raw images for storage or transfer.

Compress an image with xz
xz -T0 disk.img

# Use stronger compression for cold storage backups.

Compare two images byte-for-byte
cmp disk1.img disk2.img

# Quick equality check for cloned images of the same size.

## Troubleshooting
Show disk throughput and utilization
iostat -xz 1

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

Watch per-process I/O usage
sudo iotop

# Find which processes generate the most disk I/O.

Show per-process I/O counters
pidstat -d 1

# Track read/write activity by process over time.

Show system-wide I/O wait and block activity
vmstat 1

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

Filter kernel logs for storage messages
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
journalctl -k | egrep -i 'I/O error|blk_update_request|nvme|md'

# Kernel journal view for storage-related problems.

Interactive disk usage explorer
sudo ncdu /

# Find large paths interactively with a terminal UI.

Find large files
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
sudo lsof | grep '(deleted)'

# Useful when df is full but du cannot explain it.

Trim mounted SSD filesystems
sudo fstrim -av

# Discard unused blocks on mounted SSD-backed filesystems.

Recommended next

No recommendations yet.