Skip to content
Snippets Groups Projects
Commit 886b5671 authored by Axel Hahn's avatar Axel Hahn
Browse files

unescape regex with space

parent 7021cabc
No related branches found
No related tags found
1 merge request!80Add hooks
......@@ -14,6 +14,7 @@
# 2016-12-09 ah,ds v1.0
# 2022-01-19 ah v1.1 fixes with shellcheck
# 2022-02-09 ah v1.2 update after changes in logging
# 2022-10-07 ah v1.3 unescape regex with space to prevent "grep: warning: stray \ before white space"
# ==============================================================================
. $(dirname $0)/jobhelper.sh
......@@ -105,14 +106,14 @@ else
# sSearch="Args:|ElapsedTime|SourceFiles|SourceFileSize|RawDeltaSize"
# echo "$logfile" | grep -F "inc" >/dev/null
# if [ $? -eq 0 ]; then
# sSearch="[ADM]\ |${sSearch}"
# sSearch="[ADM] |${sSearch}"
# fi
# echo --- changes:
# grep -E "^(${sSearch})" "$logfile"
echo
# 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]*__"
......
......@@ -12,6 +12,7 @@
# 2017-01-23 ah,ds v1.1 added j_getLastBackupAge
# 2017-02-16 ah,ds v1.2 added storage helper function
# 2018-02-13 ah,ds v1.3 detect samba shares based on a flag
# 2022-10-07 ah v1.4 unescape regex with space to prevent "grep: warning: stray \ before white space"
# ================================================================================
......@@ -130,7 +131,7 @@ function j_getDirs2Backup(){
# param string path
# ------------------------------------------------------------
function j_getSetnameOfPath(){
grep "^set.*dir\ =\ $*$" "${DIRFILE}" | cut -f 1 -d "=" | sed "s#\-\-dir\ ##g"
grep "^set.*dir = $*$" "${DIRFILE}" | cut -f 1 -d "=" | sed "s#\-\-dir ##g"
}
# ------------------------------------------------------------
......@@ -172,7 +173,7 @@ function _j_getvar(){
>&2 echo "ERROR: cannot read file: ${1}. Abort."
exit 100
fi
grep "^${2}\ =\ " < "${1}"| cut -f 3- -d " "
grep "^${2} = " < "${1}"| cut -f 3- -d " "
}
# ------------------------------------------------------------
......@@ -196,14 +197,13 @@ function _j_runHooks(){
else
_hookdir="$_hookdir/on-error"
fi
for hookscript in $( ls -1a "$_hookdir" | grep -v "^\.*$" | sort )
for hookscript in $( ls -1a "$_hookdir" | grep -v "^\." | sort )
do
if [ -x "$hookscript" ]; then
echo ">>> HOOKS $_hookdir start $hookscript ..."
$hookscript
# else
# echo "SKIP: $hookscript (not executable)"
if [ -x "$_hookdir/$hookscript" ]; then
h3 "HOOK: start $_hookdir/$hookscript ..."
$_hookdir/$hookscript
else
h3 "HOOK: SKIP $_hookdir/$hookscript (not executable) ..."
fi
done
......@@ -336,36 +336,6 @@ function _j_setLogfile(){
export JOB_LOGFILE
}
# ------------------------------------------------------------
# date helper for job entries in start-time-inc/ start-time-full
# * get first the first entry or - if many - the latest entry
# * if empty: take value from start-time
# param string one of start-time-inc|start-time-full
# ------------------------------------------------------------
# function _j_fetchLatestStarttime(){
# sLatest=
# sStart=`_j_getvar ${JOBFILE} "$1" | sed "s#[\ \:\-]##g"`
# for sTime in `echo $sStart | sed "s#,# #g"`
# do
# if [ -z $sLatest ]; then
# sLatest=$sTime
# fi
# if [ $sTime -le `date +%H%M` ]; then
# sLatest=$sTime
# fi
# done
# if [ -z $sLatest ]; then
# $sLatest=`_j_getvar ${JOBFILE} "start-time" | sed "s#[\ \:\-]##g"`
# fi
# if [ -z $sLatest ]; then
# color error
# echo ERROR: missing start time info for $1
# color reset
# exit 1
# fi
# echo $sLatest
# }
# ------------------------------------------------------------
# check if a binary exists - and abort if not
# param string name of file
......
......@@ -12,6 +12,7 @@
# 2017-03-27 ..... v1.0 restore
# 2022-01-20 v1.1 fixes with shellcheck
# 2022-03-17 v1.2 WIP: add lines with prefix __DB__
# 2022-10-07 ah v1.3 unescape regex with space to prevent "grep: warning: stray \ before white space"
# ================================================================================
if [ -z "$BACKUP_TARGETDIR" ]; then
......@@ -108,7 +109,7 @@ function doBackup(){
loadInstance "$COUCHDB_INSTANCE"
echo "--- instance: $COUCHDB_INSTANCE"
if curl --head -X GET "$COUCHDB_URL" 2>/dev/null | grep "^HTTP.*\ 200\ "; then
if curl --head -X GET "$COUCHDB_URL" 2>/dev/null | grep "^HTTP.* 200 "; then
_doBackupOfSingleInstance
......@@ -186,7 +187,7 @@ function restoreByFile(){
loadInstance "$COUCHDB_INSTANCE"
echo "connect $couchdbhost on port $couchdbport with user $couchdbuser"
if ! curl --head -X GET "$COUCHDB_URL" 2>/dev/null | grep "^HTTP.*\ 200\ " >/dev/null; then
if ! curl --head -X GET "$COUCHDB_URL" 2>/dev/null | grep "^HTTP.* 200 " >/dev/null; then
color error
echo ERROR: couch DB instance is not available
curl -X GET "$COUCHDB_URL"
......
......@@ -20,6 +20,7 @@
# 2022-04-07 v1.5 check archive file, not only seq file
# 2022-04-14 v1.6 backup security infos (no restore yet)
# 2022-04-21 v1.7 restore security infos
# 2022-10-07 ah v1.8 unescape regex with space to prevent "grep: warning: stray \ before white space"
# ================================================================================
if [ -z "$BACKUP_TARGETDIR" ]; then
......@@ -123,7 +124,7 @@ function doBackup(){
loadInstance "$COUCHDB_INSTANCE"
echo "--- instance: $COUCHDB_INSTANCE"
if curl --head -X GET "$COUCH_URL" 2>/dev/null | grep "^HTTP.*\ 200\ "; then
if curl --head -X GET "$COUCH_URL" 2>/dev/null | grep "^HTTP.* 200 "; then
echo OK, connected.
sleep 2
_doBackupOfSingleInstance
......@@ -303,7 +304,7 @@ function restoreByFile(){
if [ $bFastMode -eq 0 ]; then
echo connect $couchdbhost on port $couchdbport with user $couchdbuser
curl --head -X GET $COUCH_URL 2>/dev/null | grep "^HTTP.*\ 200\ " >/dev/null
curl --head -X GET $COUCH_URL 2>/dev/null | grep "^HTTP.* 200 " >/dev/null
if [ $? -ne 0 ]; then
color error
echo ERROR: couch DB instance is not available
......
......@@ -13,6 +13,7 @@
# 2021-12-13 ah v1.1 detect config path
# 2021-12-14 ah v1.2 detect sbin path to execute slapcat without path
# 2022-03-17 v1.3 WIP: add lines with prefix __DB__
# 2022-10-07 ah v1.4 unescape regex with space to prevent "grep: warning: stray \ before white space"
# ================================================================================
......@@ -76,7 +77,7 @@ function doLdapBackup(){
for cfgname in $(ldapsearch -Y EXTERNAL -H ldapi:/// -s base -b '' -LLL configContext | grep "configContext" | cut -f 2 -d ":")
do
echo DN $cfgname
cfg2=$(echo $cfgname | sed "s#[\ =,]#_#g")
cfg2=$(echo $cfgname | sed "s#[ =,]#_#g")
outfile=$(hostname)_ldap_olc_config__$(get_outfile ${cfg2}).ldif
dump_ldap "$cfgname" "$BACKUP_TARGETDIR/$outfile"
......@@ -88,7 +89,7 @@ function doLdapBackup(){
for cfgname in $(ldapsearch -Y EXTERNAL -H ldapi:/// -s base -b "" -LLL "namingContexts" | grep "namingContexts" | cut -f 2 -d ":")
do
echo DN $cfgname
cfg2=`echo $cfgname | sed "s#[\ =,]#_#g"`
cfg2=`echo $cfgname | sed "s#[ =,]#_#g"`
outfile=$(hostname)_ldap_data__$(get_outfile ${cfg2}).ldif
dump_ldap "$cfgname" "$BACKUP_TARGETDIR/$outfile"
......
......@@ -8,6 +8,7 @@
# --------------------------------------------------------------------------------
# ah - Axel Hahn <axel.hahn@iml.unibe.ch>
# 2021-05-19 ah v0.0 INIT ... WIP
# 2022-10-07 ah v1.1 unescape regex with space to prevent "grep: warning: stray \ before white space"
# ================================================================================
......@@ -211,7 +212,7 @@
local _date=
echo "--- Existing snapshots:"
t_restoreDoShowVolumes \
| grep -E "(Full|Incremental).*[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\ " \
| grep -E "(Full|Incremental).*[0-9][0-9]:[0-9][0-9]:[0-9][0-9] " \
| sort -u > $tmpoutVolumes
if [ `cat $tmpoutVolumes | wc -l` -eq 0 ]; then
color error
......
......@@ -32,6 +32,7 @@
# 2022-02-10 ah v2.2 update logging (removing tee)
# 2022-10-01 ah v2.3 customize prune and verify action
# 2022-10-04 ah v2.4 prune and verify are non directory based
# 2022-10-07 ah v2.5 unescape regex with space to prevent "grep: warning: stray \ before white space"
# ================================================================================
......@@ -360,11 +361,11 @@ function setAction(){
if [ ! -z $backupid ]; then
for sItem in `_j_getvar ${DIRFILE} "${backupid}\-\-include" | sed "s#\ #${sSpaceReplace}#g"`
for sItem in `_j_getvar ${DIRFILE} "${backupid}\-\-include" | sed "s# #${sSpaceReplace}#g"`
do
ARGS_BACKUP="${ARGS_BACKUP} $( t_getParamInlude $sItem)"
done
for sItem in `_j_getvar ${DIRFILE} "${backupid}\-\-exclude" | sed "s#\ #${sSpaceReplace}#g"`
for sItem in `_j_getvar ${DIRFILE} "${backupid}\-\-exclude" | sed "s# #${sSpaceReplace}#g"`
do
ARGS_BACKUP="${ARGS_BACKUP} $( t_getParamExlude $sItem)"
done
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment