Copying and imaging disk drives
Copy image to disk with Disk Destroyer
dmesg -w # and plug in your drive; see dev name that was added
lsblk # verify device name
fdisk -l /dev<output disk> # verify device name, product name (Disk model) and size
# WARNING: this will overwrite output disk data
dd if=<input imag file img> of=/dev/<output disk> bs=1M oflag=direct status=progress
Backup disk to image file
Uses dd for copy and pv for progress bar.bar, applies compression with zstd.
#!/bin/sh -eu
INPUT_DEV=$1
sudo fdisk -l "${INPUT_DEV:?}" 1>&2
BYTES=$(sudo fdisk -l "${INPUT_DEV:?}" | head -n 1 | cut -d' ' -f5)
echo 1>&2
echo "Backup from ${INPUT_DEV:?} (${BYTES:?} bytes)" 1>&2
echo "Continue? [N/y]" 1>&2
read Y
test "$Y" = "y" || exit 0
sudo dd if="${INPUT_DEV:?}" bs=1M | pv -s "${BYTES:?}" | zstd -14
Make sure to tweak zstd's compression rate (max is 19) if you get CPU bound (100% CPU and no IO wait time) to reduce imaging time.
Use -L15M or similar option on pv to limit backup rate if source device is misbehaving under high load (e.g. USB drives).