From 3cd74416d49b931d37088fd9c7599b45bb7bd756 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Wed, 16 Jun 2021 13:59:19 +0200 Subject: [PATCH] update imlbackup server - 2 new functions * added params setactive and setinactive. * set basedir 1 level up. --- inc_config.sh.dist | 12 +++++++--- storage_helper.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/inc_config.sh.dist b/inc_config.sh.dist index 3bbc0be..6575ca2 100644 --- a/inc_config.sh.dist +++ b/inc_config.sh.dist @@ -8,14 +8,20 @@ typeset -i iMaxConnections=10 typeset -i iConnections + sSelfdir="$( dirname $0 )" + # directory with backup data - sBackupBasedir="/netshare/one-backup" + # sublevel 1 is a name of backup tool + # sublevel 2 is a fqdn of a backed up server + # i.e. /netshare/restic-backup/server.example.com + sBackupBasedir="/netshare" # where to store current connections - sConncectionDir="$sBackupBasedir/_active" + # sConncectionDir="${sBackupBasedir}/_active" + sConncectionDir="${sSelfdir}/_active_connections" # log - sLogdir="/opt/imlbackup/server/" + sLogdir="${sSelfdir}/log" sLogfile="$sLogdir/connections.log" diff --git a/storage_helper.sh b/storage_helper.sh index ea5cc21..dc1e71d 100755 --- a/storage_helper.sh +++ b/storage_helper.sh @@ -37,6 +37,7 @@ # value is set in _showConnectionCount iConnections=0 + # ---------------------------------------------------------------------- # FUNCTIONS # ---------------------------------------------------------------------- @@ -157,11 +158,57 @@ fi } + function _listRepodirs(){ + for mydir in $( ls -1d ${sBackupBasedir}/*/* | grep -vE '(_active|somethinglsetodisable)' ) + do + echo -n "$mydir " + test -f "$mydir/inactive.txt" && ( color error ; echo -n "(inactive)" ) + test -f "$mydir/inactive.txt" || ( color ok ; echo -n "(active)" ) + color reset + echo + done + } # ---------------------------------------------------------------------- # PUBLIC FUNCTIONS # ---------------------------------------------------------------------- + + function PUBLIC_setactive(){ + echo --- list of inactive backup repositories + _listRepodirs | grep '\(inactive\)' + echo + echo -n "Repo to activate again >" + read inputdir + if [ -f "$inputdir/inactive.txt" ]; then + cat "$inputdir/inactive.txt" + echo + echo Removing $inputdir/inactive.txt + rm -f "$inputdir/inactive.txt" + echo If it was a mistake run $( basename $0 ) setinactive + else + echo SKIP [$inputdir] + fi + echo + } + + function PUBLIC_setinactive(){ + echo --- list of backup repositories + _listRepodirs + echo + echo -n "Repo to deactivate >" + read inputdir + if [ -d "$inputdir" -a ! -f "$inputdir/inactive.txt" ]; then + echo -n "Short message >" + read mymessage + echo "$( date ) | $mymessage" >"$inputdir/inactive.txt" + ls -l "$inputdir/inactive.txt" + else + echo SKIP [$inputdir] + fi + echo + } + # return backup directory for a client function PUBLIC_getBackupdir(){ setBackupclient $1 @@ -211,8 +258,10 @@ # show used slots function PUBLIC_status(){ _showConnectionCount + echo if [ $iConnections -gt 0 ]; then - find $sConncectionDir -type f -exec ls -l {} \; + find $sConncectionDir -type f -exec ls -l {} \; | nl + echo fi exit 0 } @@ -308,6 +357,14 @@ echo " register | unregister [hostname]" echo " add/ remove slot for a backup client" echo + echo " setactive" + echo " Reactivate an inctave backup repo." + echo + echo " setinactive" + echo " Mark a backup repo as inactive." + echo " This prevents errors of missing backup data" + echo " if a host is obsolete and was shut down." + echo echo " status" echo " show current reserved slots" echo -- GitLab