Skip to content

Instantly share code, notes, and snippets.

@c5e3
Last active July 10, 2022 20:19
Show Gist options
  • Save c5e3/65991d6868e6175dccdb59dfc51d2908 to your computer and use it in GitHub Desktop.
Save c5e3/65991d6868e6175dccdb59dfc51d2908 to your computer and use it in GitHub Desktop.
#!/bin/bash
# restore with the following command:
# gunzip --stdout <filename>.img.gz | dd bs=10M of=/dev/sdX
# pv(1) is optional and provides a progress bar
# just remove it from the pipe, when you don't want it
DATE=$(date +"%Y-%m-%d_%H-%M")
GREEN='\033[1;32m'
RED='\033[1;31m'
NC='\033[0m'
if [[ "$1" == "-h" || "$1" == "--help" || "$1" == "" ]]; then
echo -e "simple dd backup tool by c5e3"
echo -e "must be run as root!"
echo -e "usage:"
echo -e "\tdd_bak.sh <sdX> <destination folder>"
exit 1
else
if [[ $EUID -ne 0 ]]; then
echo "try again as root" 1>&2
exit 1
fi
echo -ne "make backup from ${GREEN}/dev/$1${NC} to ${RED}$2${HOSTNAME}_$1_$DATE.img.gz${NC}? [y/n] "
read confirm
if [[ "$confirm" == "y" ]]; then
dd bs=10M if=/dev/$1 | pv | gzip > $2${HOSTNAME}_$DATE.img.gz
else
echo -e "${RED}no backup created!${NC}"
exit 1
fi
fi
@ruario
Copy link

ruario commented Jan 25, 2017

I have just discovered that pigz has --rsyncable built-in (from upstream, without a patch) and other similar switches such as --independent. In addition since pigz compresses using threads to make use of multiple processors and cores, you will most likely get far better performance. Finally pigz was written by Mark Adler (a co-author of the zlib compression library and gzip) so I would be fairly confident in its reliability.

So if you are planning to continue with a gzipped image or archive, pigz with appropriate switch(es), might be a better option.

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