Files
backupsd/backupsd
2023-01-11 13:44:47 +01:00

95 lines
1.8 KiB
Bash
Executable File

#! /bin/bash
VERSION="1.00"
CMD_COMPRESS='pbzip2'
verbose=false
testmode=false
bzip2=false
function isolate_checksum() {
checksum=($(echo ${1} | tr " " "\n"[0]))
#echo "checksum=${checksum}"
echo "${checksum}"
}
function start_backup {
echo "starting Backup"
sudo dd if=${DEVICE} bs=8M|pv| dd of=${FILE} bs=8M
echo "verifying..."
echo "checksum ${DEVICE}"
sha512src=$(sudo sha512sum ${DEVICE})
sha512src=$(isolate_checksum "${sha512src}")
echo "checksum ${FILE}"
sha512dest=$(sha512sum ${FILE})
sha512dest=$(isolate_checksum "${sha512dest}")
echo "sha512src= ${sha512src}"
echo "sha512dest= ${sha512dest}"
if [ "${sha512src}" = "${sha512dest}" ]; then
echo "compressing image with ${CMD_COMPRESS}"
${CMD_COMPRESS} ${FILE}
exit 0
else
echo "checksum verify failed, exiting"
exit 1
fi
}
numshift=0
while getopts ":v:h:z" opt; do
case ${opt} in
h)
echo "- help"
printhelp=true
numshift=$(($numshift +1))
;;
v)
echo "- verbose"
verbose=true
numshift=$(($numshift +1))
;;
z)
echo "- using bzip2"
bzip2=true
numshift=$(($numshift +1))
;;
?)
echo "unbekannt"
numshift=$(($numshift +1))
;;
esac
done
numshift=$(($numshift -1))
echo "shifting by ${numshift}"
if [[ ${numshift} -gt 0 ]] ; then
shift ${numshift}
shift
fi
echo "1=${1} 2=${2}"
DEVICE=${1}
FILE=${2}
#if [[ ${bzip2} -eq true ]] ; then
#if [[ echo "${bzip2}" |grep "true" ]] ; then
# echo "switching to bzip2 compression"
# CMD_COMPRESS=bzip2
#fi
echo "verbose=${verbose}"
echo "testmode=${testmode}"
echo "bzip2=${bzip2}"
echo "CMD_COMPRESS=${CMD_COMPRESS}"
echo "DEVICE=${DEVICE}"
echo "FILE=${FILE}"
#exit 0
echo "SD-Card Backup ${VERSION}"
start_backup