Skip to content

Instantly share code, notes, and snippets.

@tarnagas tarnagas/rasp-backup
Last active Jun 12, 2019

What would you like to do?
Save raspberry state as a compressed img file
#!/usr/bin/env sh
# Sample of use:
# rasp-backup /dev/sdc
set -eu
IMG_FILE=rasp.$(date +%Y%m%d.%s).img.gz
GZIP_BIN="$(which pigz)" # tries for multithread gzip
test -z "${GZIP_BIN}" && {
trap cleanup 2 3 6 15
cleanup() {
rm -rv "${IMG_FILE}"
exit 1
main() {
export LANG=en_US
echo "Creating backup: ${IMG_FILE}"
dd bs=4M status=progress if="${1}" | "${GZIP_BIN}" > "${IMG_FILE}" || {
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.