Skip to content
Snippets Groups Projects
Commit d0009ce4 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update restic plugin: verify; detect existing repo

parent bbb698ba
Branches
No related tags found
1 merge request!45update restic plugin: verify; detect existing repo
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
# ================================================================================ # ================================================================================
. $( dirname "$0" )/jobhelper.sh . $( dirname "$0" )/jobhelper.sh
. `dirname $0`/inc_bash.sh
typeset -i rcBackup=0 typeset -i rcBackup=0
typeset -i rcTransfer=0 typeset -i rcTransfer=0
...@@ -224,12 +224,16 @@ EOFbackupinfo ...@@ -224,12 +224,16 @@ EOFbackupinfo
echo echo
echo "INFO: $(date) - compress older logs" echo "INFO: $(date) - compress older logs"
echo find "${DIR_LOGS}" -name "*.log" -mtime +2 -print -exec gzip {} \; echo find "${DIR_LOGS}" -name "*.log" -mtime +2 -print -exec gzip {} \;
color cmd
find "${DIR_LOGS}" -name "*.log" -mtime +2 -print -exec gzip {} \; find "${DIR_LOGS}" -name "*.log" -mtime +2 -print -exec gzip {} \;
color reset
echo echo
echo "INFO: $(date) - cleanup logs" echo "INFO: $(date) - cleanup logs"
echo find "${DIR_LOGS}" -mtime +28 -delete -print echo find "${DIR_LOGS}" -mtime +28 -delete -print
color cmd
find "${DIR_LOGS}" -mtime +28 -delete -print find "${DIR_LOGS}" -mtime +28 -delete -print
color reset
echo echo
# ------------------------------------------------------------ # ------------------------------------------------------------
......
...@@ -111,8 +111,12 @@ else ...@@ -111,8 +111,12 @@ else
# grep -E "^(${sSearch})" "$logfile" # grep -E "^(${sSearch})" "$logfile"
echo echo
echo ">>> Summary of backed up directories:" # echo ">>> Summary of backed up directories:"
cat $logfile | grep "DIR\ " # cat $logfile | grep "DIR\ "
echo ">>> Summary of backup actions:"
cat $logfile | grep "__[A-Z][A-Z]*__"
sShort="$sShort - OK: $iOK ... Errors: $iError" sShort="$sShort - OK: $iOK ... Errors: $iError"
......
...@@ -287,7 +287,9 @@ ...@@ -287,7 +287,9 @@
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
# init repository # init repository
# param integer exitcode of command
function t_rcCheckInit(){ function t_rcCheckInit(){
echo -n "__REPO__ "
case $1 in case $1 in
0) color ok; echo "OK - the repository was created." ;; 0) color ok; echo "OK - the repository was created." ;;
*) color error; echo "Verify output above - returncode of init was $1" ;; *) color error; echo "Verify output above - returncode of init was $1" ;;
...@@ -295,24 +297,31 @@ ...@@ -295,24 +297,31 @@
color reset color reset
} }
# backup files # backup files
# param integer exitcode of command
# param string directory that was backed up
function t_rcCheckBackup(){ function t_rcCheckBackup(){
echo -n "__BACKUP__ "
case $1 in case $1 in
0) color ok; echo "OK" ;; 0) color ok; echo "OK $1" ;;
23) color error 23) color error
echo "FAILED - DIR ${2}"
echo A lock file was found. Maybe this server was rebooted while performing a backup. echo A lock file was found. Maybe this server was rebooted while performing a backup.
echo If so delete the file lockfile.lock named in the output and start $0 again. echo If so delete the file lockfile.lock named in the output and start $0 again.
;; ;;
31) color error 31) color error
echo "FAILED - DIR ${2}"
echo Maybe you it is a problem with the gpg-agent.conf echo Maybe you it is a problem with the gpg-agent.conf
ls -l ~/.gnupg/gpg-agent.conf && cat ~/.gnupg/gpg-agent.conf ls -l ~/.gnupg/gpg-agent.conf && cat ~/.gnupg/gpg-agent.conf
;; ;;
*) color error; echo "Backup error - returncode was $1" ;; *) color error; echo "FAILED - DIR ${2} - Backup error - returncode was $1" ;;
esac esac
color reset color reset
} }
# repoitory cleanup # repoitory cleanup
# param integer exitcode of command
function t_rcCheckCleanup(){ function t_rcCheckCleanup(){
echo -n "__PRUNE__ "
case $1 in case $1 in
0) color ok; echo "OK" ;; 0) color ok; echo "OK" ;;
*) color error; echo "Cleanup error - returncode was $1" ;; *) color error; echo "Cleanup error - returncode was $1" ;;
...@@ -321,7 +330,9 @@ ...@@ -321,7 +330,9 @@
} }
# restore files # restore files
# param integer exitcode of command
function t_rcCheckRestore(){ function t_rcCheckRestore(){
echo -n "__RESTORE__ "
case $1 in case $1 in
0) color ok; echo "OK" ;; 0) color ok; echo "OK" ;;
*) color error; echo "Restore error - returncode was $1" ;; *) color error; echo "Restore error - returncode was $1" ;;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
# 2022-01-06 ah v0.2 added support for Repository with REST and authentication # 2022-01-06 ah v0.2 added support for Repository with REST and authentication
# 2022-02-09 ah v0.3 show diff to last backup; update pruning # 2022-02-09 ah v0.3 show diff to last backup; update pruning
# 2022-02-09 ah v0.3 update pruning; more keep-params # 2022-02-09 ah v0.3 update pruning; more keep-params
# 2022-03-07 ah v0.4 add verify in post task
# ================================================================================ # ================================================================================
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -123,16 +124,21 @@ ...@@ -123,16 +124,21 @@
# function t_backupDoPreTasks(){ # function t_backupDoPreTasks(){
function t_backupDoPreTasks(){ function t_backupDoPreTasks(){
local _mycmd="restic init ${ARGS_DEFAULT}" if eval restic snapshots ${ARGS_DEFAULT} >/dev/null 2>&1
echo $_mycmd then
color cmd echo "__REPO__ OK, Backup repository already exists."
eval $_mycmd else
local _myrc=$? echo "Backup repository needs to be created."
color reset local _mycmd="restic init ${ARGS_DEFAULT}"
echo $_mycmd
# detect return code ... do not abort on any error. color cmd
t_rcCheckInit $_myrc eval $_mycmd
local _myrc=$?
color reset
# detect return code ... and abort on any error.
t_rcCheckInit $_myrc
fi
} }
...@@ -175,6 +181,21 @@ ...@@ -175,6 +181,21 @@
t_rcCheckCleanup $_myrc t_rcCheckCleanup $_myrc
echo echo
echo "--- VERIFY"
# param --read-data takes a long time. Maybe use an extra job with it.
# _mycmd="time restic check ${ARGS_DEFAULT} --with-cache --read-data"
_mycmd="restic check ${ARGS_DEFAULT} --with-cache"
echo $_mycmd
sleep 3
color cmd
eval $_mycmd
local _myrc=$?
color reset
t_rcCheckVerify $_myrc
echo
} }
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -318,35 +339,54 @@ ...@@ -318,35 +339,54 @@
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
# init repository # init repository
# param integer exitcode of command
function t_rcCheckInit(){ function t_rcCheckInit(){
echo -n "__REPO__ "
case $1 in case $1 in
0) color ok; echo "OK - the repository was created." ;; 0) color ok; echo "OK - the repository was created." ;;
1) color warning; echo "You can ignore the error if the repository was initialized already." ;; 1) color warning; echo "FAILED - You can ignore the error if the repository was initialized already." ;;
*) color error; echo "Verify output above - returncode of restic init was $1" ;; *) color error; echo "FAILED - Verify output above - returncode of restic init was $1" ;;
esac esac
color reset color reset
} }
# backup files # backup files
# param integer exitcode of command
# param string directory that was backed up
function t_rcCheckBackup(){ function t_rcCheckBackup(){
echo -n "__BACKUP__ "
case $1 in case $1 in
0) color ok; echo "OK" ;; 0) color ok; echo "OK - DIR ${2}" ;;
1) color error; echo "Unable to connect with restic repository." ;; 1) color error; echo "FAILED - DIR ${2} - Unable to connect with restic repository." ;;
*) color error; echo "Backup error - returncode was $1" ;; *) color error; echo "FAILED - DIR ${2} - Backup error - returncode was $1" ;;
esac esac
color reset color reset
} }
# repository cleanup # repository cleanup
# param integer exitcode of command
function t_rcCheckCleanup(){ function t_rcCheckCleanup(){
echo -n "__PRUNE__ "
case $1 in case $1 in
0) color ok; echo "OK" ;; 0) color ok; echo "OK" ;;
*) color error; echo "Cleanup error - returncode was $1" ;; *) color error; echo "FAILED ${2} - Cleanup error - returncode was $1" ;;
esac
color reset
}
# verify backup data
# param integer exitcode of command
function t_rcCheckVerify(){
echo -n "__VERIFY__ "
case $1 in
0) color ok; echo "OK" ;;
*) color error; echo "FAILED - returncode was $1" ;;
esac esac
color reset color reset
} }
# restore files # restore files
# param integer exitcode of command
function t_rcCheckRestore(){ function t_rcCheckRestore(){
echo -n "__RESTORE__ "
case $1 in case $1 in
0) color ok; echo "OK" ;; 0) color ok; echo "OK" ;;
*) color error; echo "Restore error - returncode was $1" ;; *) color error; echo "Restore error - returncode was $1" ;;
......
...@@ -312,17 +312,8 @@ ...@@ -312,17 +312,8 @@
color reset color reset
echo echo
t_rcCheckBackup $myrc t_rcCheckBackup $myrc "${BACKUP_DIR}"
if [ $myrc -ne 0 ]; then
color error
echo DIR ERROR ${BACKUP_DIR} rc=$myrc during file transfer
else
color ok
echo DIR OK ${BACKUP_DIR} was successful.
fi
color reset
fi fi
echo echo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment