Initial commit

master
Ringo Wantanabe 7 years ago
commit 861d0ee4d5
No known key found for this signature in database
GPG Key ID: C1C1CD34CF2907B2

@ -0,0 +1,48 @@
#!/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

@ -0,0 +1,15 @@
#!/bin/bash
if [[ -f "$1" ]]; then
[[ `stat -c "%a" "$1"` != 444 ]] && echo "WARNING: $1 permissions invalid"
[[ `stat -c "%a" "$1.sha256"` != 444 ]] && echo "WARNING: $1.sha256 permissions invalid"
if sha256sum -c "$1.sha256" && gpg --verify "$1.sig"; then
echo " -> Okay"
else
echo "ERROR - Validity check failed"
exit 1
fi
else
echo "ERROR - File not found"
exit 1
fi

@ -0,0 +1,33 @@
#!/bin/bash
sudo echo ">>> Initialising"
if [[ `id -u` == 0 ]]; then
echo "WARNING: Running as root? This might not be what you want..."
fi
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
echo ">>> Checking validity of image"
if $SCRIPTPATH/disk-backup-check "$1"; then
if stat "$2"; then
sudo umount "$2" &> /dev/null
set -e
set -o pipefail
echo ">>> Will restore $1 to $2"
read -p "Is this okay (y/N)? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
if cat "$1" | openssl aes-192-cbc -salt -d | gunzip -c | sudo dd conv=sync,noerror "of=$2" status=progress; then
echo ">>> Done"
else
echo "ERROR - Failure, corruption likely"
fi
else
echo "Doing nothing"
fi
else
echo "ERROR - No such device"
fi
fi
Loading…
Cancel
Save