added config checks
This commit is contained in:
parent
1c3b17ee3f
commit
e43bdd9458
32
btrbk
32
btrbk
|
@ -81,9 +81,9 @@ function runFullRestore {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if ! [ -e "/etc/btrbk.conf" ]; then
|
if ! [ -e "/etc/btrbk.conf" ]; then
|
||||||
rclone copy $rcloneDir"config/btrbk.conf" "/etc/"
|
rclone copy $rcloneDir"config/btrbk.conf" "/tmp/"
|
||||||
fi
|
fi
|
||||||
source /etc/btrbk.conf
|
source /tmp/btrbk.conf
|
||||||
read -e -r -p "Import GPG key?[y/N]: " gpgtest
|
read -e -r -p "Import GPG key?[y/N]: " gpgtest
|
||||||
case "$gpgtest" in
|
case "$gpgtest" in
|
||||||
[yY])
|
[yY])
|
||||||
|
@ -92,7 +92,7 @@ function runFullRestore {
|
||||||
read -e -r -p "Secretkey: " gpgPriv
|
read -e -r -p "Secretkey: " gpgPriv
|
||||||
[ ! -f "$gpgPriv" ] && echo "Not a File" && continue
|
[ ! -f "$gpgPriv" ] && echo "Not a File" && continue
|
||||||
while true; do
|
while true; do
|
||||||
read -e -r -p "Passphrase: " gpgPass
|
read -e -r -s -p "Passphrase: " gpgPass
|
||||||
gpg --pinentry-mode=loopback --passphrase "$gpgPass" --import $gpgPriv > /dev/null 2>&1 && break
|
gpg --pinentry-mode=loopback --passphrase "$gpgPass" --import $gpgPriv > /dev/null 2>&1 && break
|
||||||
echo "Wrong Passphrase or file is not a valid secret key"
|
echo "Wrong Passphrase or file is not a valid secret key"
|
||||||
done
|
done
|
||||||
|
@ -145,6 +145,8 @@ function getSnap {
|
||||||
|
|
||||||
function testConf {
|
function testConf {
|
||||||
source /etc/btrbk.conf
|
source /etc/btrbk.conf
|
||||||
|
[[ "${RCLONEDIR}" != */ ]] && RCLONEDIR="${RCLONEDIR}/"
|
||||||
|
[[ "${SNAPDIR}" != */ ]] && SNAPDIR="${SNAPDIR}/"
|
||||||
if [ -z ${rDate+x} ]; then
|
if [ -z ${rDate+x} ]; then
|
||||||
if ! date -d "$rDate" > /dev/null 2>&1; then
|
if ! date -d "$rDate" > /dev/null 2>&1; then
|
||||||
echo "date is in wrong format: YYYY-MM-DD"
|
echo "date is in wrong format: YYYY-MM-DD"
|
||||||
|
@ -170,10 +172,13 @@ function testConf {
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDate {
|
function testDate {
|
||||||
if [ $BKCYCLE = "weekly" ]; then
|
if [ "$BKCYCLE" = "weekly" ]; then
|
||||||
local dateType = "+%u"
|
local dateType = "+%u"
|
||||||
elif [ $BKCYCLE = "monthly" ]; then
|
elif [ "$BKCYCLE" = "monthly" ]; then
|
||||||
local dateType = "+%d"
|
local dateType = "+%d"
|
||||||
|
else
|
||||||
|
echo "BKCYCLE not correctly configured"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
for i in ${!BKRETENTION[@]}; do
|
for i in ${!BKRETENTION[@]}; do
|
||||||
if [ `date $dateType` = ${BKRETENTION[$i]} ]; then
|
if [ `date $dateType` = ${BKRETENTION[$i]} ]; then
|
||||||
|
@ -183,6 +188,13 @@ function testDate {
|
||||||
bkRun "incremental"
|
bkRun "incremental"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testRoot {
|
||||||
|
if ! [ $(id -u) = 0 ]; then
|
||||||
|
echo "Please run with root privileges"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function end {
|
function end {
|
||||||
echo "finished in $(( ($(date +%s) - startDate) / 60 )) min"
|
echo "finished in $(( ($(date +%s) - startDate) / 60 )) min"
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -202,7 +214,7 @@ function echoHelp {
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
options=$(getopt -l "backup,force,date::,restore::,full-restore::,help" -o "bfx::h" -- "$@")
|
options=$(getopt -l "backup,force,date::,restore::,full-restore::,help" -o "bfh" -- "$@")
|
||||||
eval set -- "$options"
|
eval set -- "$options"
|
||||||
for i in ${!options[@]}; do
|
for i in ${!options[@]}; do
|
||||||
case $1 in
|
case $1 in
|
||||||
|
@ -219,7 +231,13 @@ for i in ${!options[@]}; do
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$fullRestore" = true ]; then
|
if [ "$fullRestore" = true ]; then
|
||||||
|
testRoot
|
||||||
runFullRestore
|
runFullRestore
|
||||||
else
|
elif [ "$backup" = true ] || [ "$restore" = true ]; then
|
||||||
|
testRoot
|
||||||
testConf
|
testConf
|
||||||
|
else
|
||||||
|
echo "No valid option given."
|
||||||
|
echo "Try 'btrbk --help' for more information."
|
||||||
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue