diff --git a/localdump.sh b/localdump.sh index 5b14cc32f60569d980bb4d055d9ce13f5b20d11f..c4e2decc568c5707869b05838204d30bd4a877b4 100755 --- a/localdump.sh +++ b/localdump.sh @@ -14,6 +14,7 @@ # 2021-05-18 ..... move supported backup types to plugins/localdump/[service].sh # 2021-07-13 ..... remove leading ./ in localdump.sh restore # 2022-02-18 ..... WIP: use class like functions +# 2022-03-17 ..... WIP: add lines with prefix __DB__ # ====================================================================== # --- variables: @@ -86,9 +87,7 @@ # $myrc is last returncode - set in fetchrc if [ $myrc -eq 0 ]; then - echo -n "gzip ... " - # compress_file "$_outfile" - echo -n "compressing $1 ... " + echo -n "gzip $1 ... " gzip -9 -f "${1}" fetchrc >/dev/null if [ $myrc -eq 0 ]; then @@ -99,7 +98,7 @@ else cecho error "ERROR occured while dumping - no gzip" fi - ls -l "$_outfile"* + echo -n "__DB__$SERVICENAME INFO: backup to " ls -l "$_outfile"* 2>&1 echo } diff --git a/plugins/localdump/couchdb.sh b/plugins/localdump/couchdb.sh index cfb8b6fad71d6be4b394007e126d0c3922f1e768..ac858da3d72c7c84d5b762f4a396299ad26a205c 100755 --- a/plugins/localdump/couchdb.sh +++ b/plugins/localdump/couchdb.sh @@ -11,6 +11,7 @@ # 2017-03-24 ah,ds v0.9 backup # 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__ # ================================================================================ if [ -z "$BACKUP_TARGETDIR" ]; then @@ -146,16 +147,17 @@ function _doBackupOfSingleInstance(){ python ${dirPythonPackages}/couchdb/tools/dump.py "${COUCHDB_URL}/${dbname}" >"${OUTFILE}" fetchrc + db._compressDumpfile "${OUTFILE}" # $myrc is last returncode - set in fetchrc - if [ $myrc -eq 0 ]; then - echo -n "gzip ... " - compress_file "$OUTFILE" - else - echo "ERROR occured - no gzip" - fi - ls -l "$OUTFILE"* - echo + # if [ $myrc -eq 0 ]; then + # echo -n "gzip ... " + # compress_file "$OUTFILE" + # else + # echo "ERROR occured - no gzip" + # fi + # ls -l "$OUTFILE"* + # echo done } @@ -268,10 +270,10 @@ if [ $rc -eq 0 ]; then else rc=0 - echo "SKIP: couchdb seems not to be here" + echo "__DB__$SERVICENAME SKIP: couchdb seems not to be here" fi -echo "$0 $* [couchdb] final returncode rc=$rc" +echo "__DB__$SERVICENAME INFO: $0 $* [couchdb] final returncode rc=$rc" # -------------------------------------------------------------------------------- diff --git a/plugins/localdump/couchdb2.sh b/plugins/localdump/couchdb2.sh index 59fdeac0d27da2c27e5f68e3c218484686b816b2..7c0c6ff742a603deee0b5c688d04909a63f4f22a 100755 --- a/plugins/localdump/couchdb2.sh +++ b/plugins/localdump/couchdb2.sh @@ -16,6 +16,7 @@ # 2021-10-11 ..... v1.2 added fastmode in restore: no test connect, do not # delete DB before create request # 2022-01-20 v1.3 fixes with shellcheck +# 2022-03-17 v1.4 WIP: add lines with prefix __DB__ # ================================================================================ if [ -z "$BACKUP_TARGETDIR" ]; then @@ -171,6 +172,7 @@ function _doBackupOfSingleInstance(){ typeset -i iDbTotal=$( cat "$dblist" | wc -l ) typeset -i iDb=0 + typeset -i iDbCount=0 echo echo " DUMP databases of instance ${COUCHDB_INSTANCE}: $iDbTotal databases" @@ -209,6 +211,7 @@ function _doBackupOfSingleInstance(){ compress_file "$OUTFILE" fetchrc if [ $myrc -eq 0 ]; then + iDbCount+=1 cp "${OUTFILE}"* "${ARCHIVFILE}" && echo "${sSequenceCurrent}">"${SEQFILE}" ls -l "${ARCHIVFILE}" "${SEQFILE}" fi @@ -220,6 +223,8 @@ function _doBackupOfSingleInstance(){ fi done rm -f "$dblist" + echo "__DB__$SERVICENAME INFO: ${COUCHDB_INSTANCE} - backed up $iDbCount dbs of $iDbTotal total" + } # ---------- RESTORE @@ -344,10 +349,10 @@ if [ $rc -eq 0 ]; then else rc=0 - echo "SKIP: couchdb2 config does not seem to be here" + echo "__DB__$SERVICENAME SKIP: couchdb2 config does not seem to be here" fi -echo $0 $* [couchdb2] final returncode rc=$rc +echo "__DB__$SERVICENAME INFO: $0 $* [$SERVICENAME] final returncode rc=$rc" # -------------------------------------------------------------------------------- diff --git a/plugins/localdump/ldap.sh b/plugins/localdump/ldap.sh index bab4d9eeaefb39834c8b049ad38189b652424db6..6c3cb8d6ed59410241a1ba932c555f3359330ae9 100755 --- a/plugins/localdump/ldap.sh +++ b/plugins/localdump/ldap.sh @@ -12,6 +12,7 @@ # 202_-__-__ ..... v1.0 detect config path # 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__ # ================================================================================ @@ -116,11 +117,11 @@ j_requireBinary "slapcat" 1 j_requireProcess "slapd" 1 -ls $LDAP_CONF_DIR_PATH >/dev/null +ls $LDAP_CONF_DIR_PATH >/dev/null 2>&1 if [ $rc -ne 0 ]; then rc=0 - echo "SKIP: LDAP seems not to be here" + echo "__DB__$SERVICENAME SKIP: LDAP seems not to be here" else if [ "$1" = "restore" ]; then echo @@ -131,6 +132,6 @@ else fi fi -echo $0 $* [ldap] final returncode rc=$rc +echo "__DB__$SERVICENAME INFO: $0 $* [ldap] final returncode rc=$rc" # -------------------------------------------------------------------------------- diff --git a/plugins/localdump/mysql.sh b/plugins/localdump/mysql.sh index 5f9d81af0a4dce119479d5021044915457a08488..5c876bd1dc9fb8ea953b1f798b3810d6e9a90963 100755 --- a/plugins/localdump/mysql.sh +++ b/plugins/localdump/mysql.sh @@ -12,6 +12,7 @@ # 2022-01-20 ah v1.1 fixes with shellcheck # 2022-02-14 ah v2.0 rewrite with class like functions # 2022-02-18 ah v2.1 WIP: added counters +# 2022-03-17 v1.2 WIP: add lines with prefix __DB__ # ================================================================================ if [ -z "$LOCALDUMP_LOADED" ]; then @@ -92,6 +93,7 @@ function mysql.db.dump(){ fetchrc >/dev/null test $myrc -eq 0 && mysql_COUNT_DUMPS+=1 test $rc -eq 0 || mysql_COUNT_ERRORS+=1 + test $rc -eq 0 } # import [file] --> [database] @@ -260,13 +262,13 @@ EOSTATUS "${SERVICENAME}".check 1 if ! "${SERVICENAME}".available; then - echo "INFO: service [$SERVICENAME] is not avilable on this machine." + echo "__DB__$SERVICENAME SKIP: service [$SERVICENAME] is not avilable on this machine." fi action=$1 shift 1 "${SERVICENAME}.$action" $* -echo "INFO: $0 $action $* [$SERVICENAME] final returncode rc=$rc" +echo "__DB__$SERVICENAME INFO: $0 $action $* [$SERVICENAME] final returncode rc=$rc" # -------------------------------------------------------------------------------- diff --git a/plugins/localdump/pgsql.sh b/plugins/localdump/pgsql.sh index 5a896508dc34ba4d221020a984b3e0a7abfdd1ba..9dafcc7d1a278f574c4205e7ce4acafa7274404c 100755 --- a/plugins/localdump/pgsql.sh +++ b/plugins/localdump/pgsql.sh @@ -11,6 +11,7 @@ # 2016-11-10 ah,ds v1.0 # 2017-03-29 ..... v1.1 added restore # 2022-01-20 v1.2 fixes with shellcheck +# 2022-03-17 v1.3 WIP: add lines with prefix __DB__ # ================================================================================ if [ -z "$BACKUP_TARGETDIR" ]; then @@ -23,6 +24,7 @@ fi # CONFIG # -------------------------------------------------------------------------------- + SERVICEFOUND=0 # unix user of postgres database PGUSER=postgres @@ -31,6 +33,15 @@ fi # FUNCTION # -------------------------------------------------------------------------------- +function checkRequirements(){ + j_requireBinary "pg_dump" 1 + j_requireProcess "postgres" 1 + + # set flag and reset return code + test $rc -eq 0 && SERVICEFOUND=1 + rc=0 +} + function doPgsqlBackup(){ create_targetdir @@ -49,16 +60,19 @@ function doPgsqlBackup(){ su ${PGUSER} -c "pg_dump -Fp ${DATABASE} >$OUTFILE" fetchrc - if [ $myrc -eq 0 ]; then - echo -n "compress ... " - compress_file "$OUTFILE" - else - color error - echo "ERROR occured - no gzip" - color reset - # mv $OUTFILE $OUTFILE - fi - ls -l "$OUTFILE"* + db._compressDumpfile "$OUTFILE" + + # if [ $myrc -eq 0 ]; then + # echo -n "compress ... " + # compress_file "$OUTFILE" + # else + # color error + # echo "ERROR occured - no gzip" + # color reset + # # mv $OUTFILE $OUTFILE + # echo "__DB__$SERVICENAME INFO: backed up ${DATABASE}" + # fi + # ls -l "$OUTFILE"* echo done } @@ -110,23 +124,32 @@ function restoreByFile(){ # -------------------------------------------------------------------------------- # ----- requirements - j_requireBinary "pg_dump" 1 - j_requireProcess "postgres" 1 - - if [ $rc -ne 0 ]; then - rc=0 - echo "SKIP: postgres seems not to be here" - else - if [ "$1" = "restore" ]; then - shift 1 - restoreByFile $* - - else - doPgsqlBackup - fi - - fi +checkRequirements >/dev/null 2>&1 +if [ $SERVICEFOUND -eq 0 ]; then + echo "__DB__$SERVICENAME INFO: service [$SERVICENAME] is not avilable on this machine." +fi - echo "$0 $* [postgres] final returncode rc=$rc" +case $1 in + check) + # repeat check ... but show output + echo + echo Details: + checkRequirements + echo + ;; + backup) + test $SERVICEFOUND -eq 1 && doPgsqlBackup + ;; + restore) + shift 1 + test $SERVICEFOUND -eq 1 && restoreByFile $* + ;; + *) + echo ERROR: wrong syntax: + echo $0 $* + exit 1 + esac + +echo "__DB__$SERVICENAME INFO: $0 $* [$SERVICENAME] final returncode rc=$rc" # -------------------------------------------------------------------------------- diff --git a/plugins/localdump/sqlite.sh b/plugins/localdump/sqlite.sh index 1d0879bfd573f8a532f57894c4a6381ab2357df3..38e3f0935018840c7be2fb461cafb995ec2b1d88 100755 --- a/plugins/localdump/sqlite.sh +++ b/plugins/localdump/sqlite.sh @@ -11,14 +11,14 @@ # # 2018-02-02 ah,ds v1.0 first lines # 2018-02-09 ah,ds v1.1 write a .meta file after successful backup +# 2022-03-17 v1.2 WIP: add lines with prefix __DB__ # ================================================================================ -if [ -z $BACKUP_TARGETDIR ]; then - echo ERROR: you cannot start `basename $0` directly +if [ -z "$BACKUP_TARGETDIR" ]; then + echo "ERROR: you cannot start $(basename $0) directly" rc=$rc+1 exit 1 fi - # -------------------------------------------------------------------------------- # CONFIG # -------------------------------------------------------------------------------- @@ -34,37 +34,39 @@ function doSqliteBackup(){ create_targetdir - for DATABASE_FILE in `_j_getvar ${FILEDEFS} "sqlite"` + for DATABASE_FILE in $(_j_getvar ${FILEDEFS} "sqlite") do - echo --- database $DATABASE_FILE - if [ ! -f $DATABASE_FILE ]; then + echo "--- database $DATABASE_FILE" + if [ ! -f "$DATABASE_FILE" ]; then color error - echo ERROR: given database file does not exist: $DATABASE_FILE + echo "ERROR: given database file does not exist: $DATABASE_FILE" color reset rc=$rc+1 else - file $DATABASE_FILE | cut -f 2 -d ":" | fgrep -i "sqlite" >/dev/null + file "$DATABASE_FILE" | cut -f 2 -d ":" | grep -i "sqlite" >/dev/null if [ $? -ne 0 ]; then color error - echo ERROR: given database file is not a sqlite database $DATABASE_FILE + echo "ERROR: given database file is not a sqlite database $DATABASE_FILE" color reset rc=$rc+1 else - TARGET=`get_outfile ${DATABASE_FILE}` - TARGET=${BACKUP_TARGETDIR}/`echo ${TARGET} | sed "s#/#_#g"`.sql + TARGET=$(get_outfile ${DATABASE_FILE}) + TARGET=${BACKUP_TARGETDIR}/$(echo ${TARGET} | sed "s#/#_#g").sql META=${TARGET}.gz.meta echo target: $TARGET - sqlite3 $DATABASE_FILE .dump >${TARGET} + sqlite3 "$DATABASE_FILE" .dump >"${TARGET}" fetchrc + db._compressDumpfile "${TARGET}" + # $myrc is last returncode - set in fetchrc - if [ $myrc -eq 0 ]; then - echo -n "gzip ... " - compress_file ${TARGET} - echo $DATABASE_FILE >${META} - else - echo "ERROR occured - no gzip" - fi - ls -l ${TARGET}* + # if [ $myrc -eq 0 ]; then + # echo -n "gzip ... " + # compress_file "${TARGET}" + # echo "$DATABASE_FILE" >"${META}" + # else + # echo "ERROR occured - no gzip" + # fi + # ls -l ${TARGET}* fi fi @@ -110,7 +112,7 @@ function restoreByFile(){ # ----- check requirements j_requireBinary "sqlite3" 1 -if [ ! -f $FILEDEFS ]; then +if [ ! -f "$FILEDEFS" ]; then echo "INFO: file definitions $FILEDEFS do not exist." rc=$rc+1 fi @@ -130,6 +132,6 @@ else fi fi -echo $0 $* [sqlite] final returncode rc=$rc +echo "__DB__$SERVICENAME INFO: $0 $* [$SERVICENAME] final returncode rc=$rc" # --------------------------------------------------------------------------------