Skip to content

Instantly share code, notes, and snippets.

@tekk
Created October 21, 2025 11:50
Show Gist options
  • Select an option

  • Save tekk/0af80b860c93c144fac81dc6eaa087df to your computer and use it in GitHub Desktop.

Select an option

Save tekk/0af80b860c93c144fac81dc6eaa087df to your computer and use it in GitHub Desktop.

Backup and restore like a pro

Use Clonezilla!

But if you want to do it manually in the shell, with post-quantum encryption, do it this way:

Prerequsities

  • zstd - ZStandard is a real-time compression algorithm with compression ratios similar to brotli or standard deflate (zip)
  • rust & cargo - cargo is needed to install rage (use package manager of your choice)

Then:

cargo install rage

1. Block devices

Backup:

sudo dd if=/dev/sdX bs=4M status=progress iflag=direct conv=sparse | zstd -T0 -5 --progress | rage --encrypt --passphrase > "backup_$(date +'%Y-%m-%d_%H-%M-%S').img.zst.age"

Here I'm using symmetric passphrase cypher, but I strongly encourage you to generate a pub/pri keys with rage and use those for assymetric encryption (you can encrypt for decryptyng not just other ppl but yourself as well, when you're specifying recipients).

  • Note about ZStandard compression ratio:

The -5 in the zstd arguments is the compression ratio. The sweet spots are:

  • Level 3 – 5: Best trade-off between speed and ratio, use for Single-threaded, average CPU or SBCs. 3 gives very good ratio with real-time compression
  • Level 7 – 9: Exploits extra cores well, diminishing returns until level 9, Multi-threaded, modern CPU (6+ cores)

Restore:

rage --decrypt -o - backup_*.img.zst.age | zstd -d --stdout | sudo dd of=/dev/sdX bs=4M status=progress oflag=direct

Folders

Backup:

tar -cf - /path/to/folder | zstd -T0 -5 --progress | rage --encrypt --passphrase > "backup_$(date +'%Y-%m-%d_%H-%M-%S').tar.zst.age"

Restore:

rage --decrypt -o - your_backup_file.tar.zst.age | zstd -d --stdout --progress | tar -xf -

Hope that someone will find this useful.

Author: @tekk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment