Last active
June 12, 2019 09:45
-
-
Save tarnagas/3c8d08223c005ab2c9029df5c19bb371 to your computer and use it in GitHub Desktop.
Save raspberry state as a compressed img file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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