Skip to content

Instantly share code, notes, and snippets.

@tarnagas
Last active June 12, 2019 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarnagas/3c8d08223c005ab2c9029df5c19bb371 to your computer and use it in GitHub Desktop.
Save tarnagas/3c8d08223c005ab2c9029df5c19bb371 to your computer and use it in GitHub Desktop.
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}" && {
GZIP_BIN=gzip
}
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}" || {
cleanup
}
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment