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

Merge branch 'update-localdump-to-classlike-functions' into 'master'

update restic plugin: verify; detect existing repo

See merge request !45
parents 8359a2a2 d0009ce4
No related branches found
No related tags found
1 merge request!45update restic plugin: verify; detect existing repo
......@@ -17,7 +17,7 @@
# ================================================================================
. $( dirname "$0" )/jobhelper.sh
. `dirname $0`/inc_bash.sh
typeset -i rcBackup=0
typeset -i rcTransfer=0
......@@ -224,12 +224,16 @@ EOFbackupinfo
echo
echo "INFO: $(date) - compress older logs"
echo find "${DIR_LOGS}" -name "*.log" -mtime +2 -print -exec gzip {} \;
color cmd
find "${DIR_LOGS}" -name "*.log" -mtime +2 -print -exec gzip {} \;
color reset
echo
echo "INFO: $(date) - cleanup logs"
echo find "${DIR_LOGS}" -mtime +28 -delete -print
color cmd
find "${DIR_LOGS}" -mtime +28 -delete -print
color reset
echo
# ------------------------------------------------------------
......
......@@ -111,8 +111,12 @@ else
# grep -E "^(${sSearch})" "$logfile"
echo
echo ">>> Summary of backed up directories:"
cat $logfile | grep "DIR\ "
# echo ">>> Summary of backed up directories:"
# cat $logfile | grep "DIR\ "
echo ">>> Summary of backup actions:"
cat $logfile | grep "__[A-Z][A-Z]*__"
sShort="$sShort - OK: $iOK ... Errors: $iError"
......
......@@ -287,7 +287,9 @@
# --------------------------------------------------------------------------------
# init repository
# param integer exitcode of command
function t_rcCheckInit(){
echo -n "__REPO__ "
case $1 in
0) color ok; echo "OK - the repository was created." ;;
*) color error; echo "Verify output above - returncode of init was $1" ;;
......@@ -295,24 +297,31 @@
color reset
}
# backup files
# param integer exitcode of command
# param string directory that was backed up
function t_rcCheckBackup(){
echo -n "__BACKUP__ "
case $1 in
0) color ok; echo "OK" ;;
0) color ok; echo "OK $1" ;;
23) color error
echo "FAILED - DIR ${2}"
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.
;;
31) color error
echo "FAILED - DIR ${2}"
echo Maybe you it is a problem with the 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
color reset
}
# repoitory cleanup
# param integer exitcode of command
function t_rcCheckCleanup(){
echo -n "__PRUNE__ "
case $1 in
0) color ok; echo "OK" ;;
*) color error; echo "Cleanup error - returncode was $1" ;;
......@@ -321,7 +330,9 @@
}
# restore files
# param integer exitcode of command
function t_rcCheckRestore(){
echo -n "__RESTORE__ "
case $1 in
0) color ok; echo "OK" ;;
*) color error; echo "Restore error - returncode was $1" ;;
......
......@@ -11,6 +11,7 @@
# 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 update pruning; more keep-params
# 2022-03-07 ah v0.4 add verify in post task
# ================================================================================
# --------------------------------------------------------------------------------
......@@ -123,6 +124,11 @@
# function t_backupDoPreTasks(){
function t_backupDoPreTasks(){
if eval restic snapshots ${ARGS_DEFAULT} >/dev/null 2>&1
then
echo "__REPO__ OK, Backup repository already exists."
else
echo "Backup repository needs to be created."
local _mycmd="restic init ${ARGS_DEFAULT}"
echo $_mycmd
color cmd
......@@ -130,9 +136,9 @@
local _myrc=$?
color reset
# detect return code ... do not abort on any error.
# detect return code ... and abort on any error.
t_rcCheckInit $_myrc
fi
}
......@@ -175,6 +181,21 @@
t_rcCheckCleanup $_myrc
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 @@
# --------------------------------------------------------------------------------
# init repository
# param integer exitcode of command
function t_rcCheckInit(){
echo -n "__REPO__ "
case $1 in
0) color ok; echo "OK - the repository was created." ;;
1) color warning; echo "You can ignore the error if the repository was initialized already." ;;
*) color error; echo "Verify output above - returncode of restic init was $1" ;;
1) color warning; echo "FAILED - You can ignore the error if the repository was initialized already." ;;
*) color error; echo "FAILED - Verify output above - returncode of restic init was $1" ;;
esac
color reset
}
# backup files
# param integer exitcode of command
# param string directory that was backed up
function t_rcCheckBackup(){
echo -n "__BACKUP__ "
case $1 in
0) color ok; echo "OK" ;;
1) color error; echo "Unable to connect with restic repository." ;;
*) color error; echo "Backup error - returncode was $1" ;;
0) color ok; echo "OK - DIR ${2}" ;;
1) color error; echo "FAILED - DIR ${2} - Unable to connect with restic repository." ;;
*) color error; echo "FAILED - DIR ${2} - Backup error - returncode was $1" ;;
esac
color reset
}
# repository cleanup
# param integer exitcode of command
function t_rcCheckCleanup(){
echo -n "__PRUNE__ "
case $1 in
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
color reset
}
# restore files
# param integer exitcode of command
function t_rcCheckRestore(){
echo -n "__RESTORE__ "
case $1 in
0) color ok; echo "OK" ;;
*) color error; echo "Restore error - returncode was $1" ;;
......
......@@ -312,17 +312,8 @@
color reset
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
echo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment