You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.0 KiB

#!/bin/bash
sudo echo ">>> Initialising"
PREFIX=$2
if [[ ! "$PREFIX" == "" ]]; then
PREFIX=$2-
fi
if [[ `id -u` == 0 ]]; then
echo "WARNING: Running as root? This might not be what you want..."
fi
ROOT=~/.backups/disk
if [[ ! -d $ROOT ]]; then
mkdir -p $ROOT
fi
if stat "$1"; then
OUTPUT=$ROOT/$PREFIX`basename $1`-`date +%Y-%m-%d-%H%M%S`.disk
sudo umount "$1" &> /dev/null
echo ">>> Will backup disk '$1' to file $OUTPUT"
read -p "Is this okay (y/N)? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
set -e
set -o pipefail
if sudo dd "if=$1" conv=sync,noerror status=progress | gzip -9 -c | openssl aes-192-cbc -salt -e > $OUTPUT; then
echo ">>> Calculating hash"
sha256sum $OUTPUT > $OUTPUT.sha256
echo ">>> Signing image"
gpg --detach-sign -o $OUTPUT.sig $OUTPUT
echo ">>> Setting permissions"
sudo chmod 0444 $OUTPUT
sudo chmod 0444 $OUTPUT.sha256
sudo chmod 0444 $OUTPUT.sig
echo ">>> Done"
else
echo "ERROR - Stopping"
fi
else
echo "Doing nothing"
fi
else
echo "ERROR - File not found"
fi