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

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

add lines with prefix __DB__

See merge request !47
parents e43a28f2 48236889
No related branches found
No related tags found
1 merge request!47add lines with prefix __DB__
...@@ -336,7 +336,7 @@ function _j_setLogfile(){ ...@@ -336,7 +336,7 @@ function _j_setLogfile(){
# ------------------------------------------------------------ # ------------------------------------------------------------
function j_requireBinary(){ function j_requireBinary(){
# echo "CHECK binary $1" # echo "CHECK binary $1"
which "$1" >/dev/null which "$1" >/dev/null 2>&1
rcself=$? rcself=$?
if [ $rcself -ne 0 ]; then if [ $rcself -ne 0 ]; then
rc=$rc+$rcself rc=$rc+$rcself
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# 2021-05-18 ..... move supported backup types to plugins/localdump/[service].sh # 2021-05-18 ..... move supported backup types to plugins/localdump/[service].sh
# 2021-07-13 ..... remove leading ./ in localdump.sh restore # 2021-07-13 ..... remove leading ./ in localdump.sh restore
# 2022-02-18 ..... WIP: use class like functions # 2022-02-18 ..... WIP: use class like functions
# 2022-03-17 ..... WIP: add lines with prefix __DB__
# ====================================================================== # ======================================================================
# --- variables: # --- variables:
...@@ -86,9 +87,7 @@ ...@@ -86,9 +87,7 @@
# $myrc is last returncode - set in fetchrc # $myrc is last returncode - set in fetchrc
if [ $myrc -eq 0 ]; then if [ $myrc -eq 0 ]; then
echo -n "gzip ... " echo -n "gzip $1 ... "
# compress_file "$_outfile"
echo -n "compressing $1 ... "
gzip -9 -f "${1}" gzip -9 -f "${1}"
fetchrc >/dev/null fetchrc >/dev/null
if [ $myrc -eq 0 ]; then if [ $myrc -eq 0 ]; then
...@@ -99,7 +98,7 @@ ...@@ -99,7 +98,7 @@
else else
cecho error "ERROR occured while dumping - no gzip" cecho error "ERROR occured while dumping - no gzip"
fi fi
ls -l "$_outfile"* echo -n "__DB__$SERVICENAME INFO: backup to " ls -l "$_outfile"* 2>&1
echo echo
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
# 2017-03-24 ah,ds v0.9 backup # 2017-03-24 ah,ds v0.9 backup
# 2017-03-27 ..... v1.0 restore # 2017-03-27 ..... v1.0 restore
# 2022-01-20 v1.1 fixes with shellcheck # 2022-01-20 v1.1 fixes with shellcheck
# 2022-03-17 v1.2 WIP: add lines with prefix __DB__
# ================================================================================ # ================================================================================
if [ -z "$BACKUP_TARGETDIR" ]; then if [ -z "$BACKUP_TARGETDIR" ]; then
...@@ -146,16 +147,17 @@ function _doBackupOfSingleInstance(){ ...@@ -146,16 +147,17 @@ function _doBackupOfSingleInstance(){
python ${dirPythonPackages}/couchdb/tools/dump.py "${COUCHDB_URL}/${dbname}" >"${OUTFILE}" python ${dirPythonPackages}/couchdb/tools/dump.py "${COUCHDB_URL}/${dbname}" >"${OUTFILE}"
fetchrc fetchrc
db._compressDumpfile "${OUTFILE}"
# $myrc is last returncode - set in fetchrc # $myrc is last returncode - set in fetchrc
if [ $myrc -eq 0 ]; then # if [ $myrc -eq 0 ]; then
echo -n "gzip ... " # echo -n "gzip ... "
compress_file "$OUTFILE" # compress_file "$OUTFILE"
else # else
echo "ERROR occured - no gzip" # echo "ERROR occured - no gzip"
fi # fi
ls -l "$OUTFILE"* # ls -l "$OUTFILE"*
echo # echo
done done
} }
...@@ -268,10 +270,10 @@ if [ $rc -eq 0 ]; then ...@@ -268,10 +270,10 @@ if [ $rc -eq 0 ]; then
else else
rc=0 rc=0
echo "SKIP: couchdb seems not to be here" echo "__DB__$SERVICENAME SKIP: couchdb seems not to be here"
fi fi
echo "$0 $* [couchdb] final returncode rc=$rc" echo "__DB__$SERVICENAME INFO: $0 $* [couchdb] final returncode rc=$rc"
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
# 2021-10-11 ..... v1.2 added fastmode in restore: no test connect, do not # 2021-10-11 ..... v1.2 added fastmode in restore: no test connect, do not
# delete DB before create request # delete DB before create request
# 2022-01-20 v1.3 fixes with shellcheck # 2022-01-20 v1.3 fixes with shellcheck
# 2022-03-17 v1.4 WIP: add lines with prefix __DB__
# ================================================================================ # ================================================================================
if [ -z "$BACKUP_TARGETDIR" ]; then if [ -z "$BACKUP_TARGETDIR" ]; then
...@@ -171,6 +172,7 @@ function _doBackupOfSingleInstance(){ ...@@ -171,6 +172,7 @@ function _doBackupOfSingleInstance(){
typeset -i iDbTotal=$( cat "$dblist" | wc -l ) typeset -i iDbTotal=$( cat "$dblist" | wc -l )
typeset -i iDb=0 typeset -i iDb=0
typeset -i iDbCount=0
echo echo
echo " DUMP databases of instance ${COUCHDB_INSTANCE}: $iDbTotal databases" echo " DUMP databases of instance ${COUCHDB_INSTANCE}: $iDbTotal databases"
...@@ -209,6 +211,7 @@ function _doBackupOfSingleInstance(){ ...@@ -209,6 +211,7 @@ function _doBackupOfSingleInstance(){
compress_file "$OUTFILE" compress_file "$OUTFILE"
fetchrc fetchrc
if [ $myrc -eq 0 ]; then if [ $myrc -eq 0 ]; then
iDbCount+=1
cp "${OUTFILE}"* "${ARCHIVFILE}" && echo "${sSequenceCurrent}">"${SEQFILE}" cp "${OUTFILE}"* "${ARCHIVFILE}" && echo "${sSequenceCurrent}">"${SEQFILE}"
ls -l "${ARCHIVFILE}" "${SEQFILE}" ls -l "${ARCHIVFILE}" "${SEQFILE}"
fi fi
...@@ -220,6 +223,8 @@ function _doBackupOfSingleInstance(){ ...@@ -220,6 +223,8 @@ function _doBackupOfSingleInstance(){
fi fi
done done
rm -f "$dblist" rm -f "$dblist"
echo "__DB__$SERVICENAME INFO: ${COUCHDB_INSTANCE} - backed up $iDbCount dbs of $iDbTotal total"
} }
# ---------- RESTORE # ---------- RESTORE
...@@ -344,10 +349,10 @@ if [ $rc -eq 0 ]; then ...@@ -344,10 +349,10 @@ if [ $rc -eq 0 ]; then
else else
rc=0 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 fi
echo $0 $* [couchdb2] final returncode rc=$rc echo "__DB__$SERVICENAME INFO: $0 $* [$SERVICENAME] final returncode rc=$rc"
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# 202_-__-__ ..... v1.0 detect config path # 202_-__-__ ..... v1.0 detect config path
# 2021-12-13 ah v1.1 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 # 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 ...@@ -116,11 +117,11 @@ j_requireBinary "slapcat" 1
j_requireProcess "slapd" 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 if [ $rc -ne 0 ]; then
rc=0 rc=0
echo "SKIP: LDAP seems not to be here" echo "__DB__$SERVICENAME SKIP: LDAP seems not to be here"
else else
if [ "$1" = "restore" ]; then if [ "$1" = "restore" ]; then
echo echo
...@@ -131,6 +132,6 @@ else ...@@ -131,6 +132,6 @@ else
fi fi
fi fi
echo $0 $* [ldap] final returncode rc=$rc echo "__DB__$SERVICENAME INFO: $0 $* [ldap] final returncode rc=$rc"
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# 2022-01-20 ah v1.1 fixes with shellcheck # 2022-01-20 ah v1.1 fixes with shellcheck
# 2022-02-14 ah v2.0 rewrite with class like functions # 2022-02-14 ah v2.0 rewrite with class like functions
# 2022-02-18 ah v2.1 WIP: added counters # 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 if [ -z "$LOCALDUMP_LOADED" ]; then
...@@ -92,6 +93,7 @@ function mysql.db.dump(){ ...@@ -92,6 +93,7 @@ function mysql.db.dump(){
fetchrc >/dev/null fetchrc >/dev/null
test $myrc -eq 0 && mysql_COUNT_DUMPS+=1 test $myrc -eq 0 && mysql_COUNT_DUMPS+=1
test $rc -eq 0 || mysql_COUNT_ERRORS+=1 test $rc -eq 0 || mysql_COUNT_ERRORS+=1
test $rc -eq 0
} }
# import [file] --> [database] # import [file] --> [database]
...@@ -260,13 +262,13 @@ EOSTATUS ...@@ -260,13 +262,13 @@ EOSTATUS
"${SERVICENAME}".check 1 "${SERVICENAME}".check 1
if ! "${SERVICENAME}".available; then 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 fi
action=$1 action=$1
shift 1 shift 1
"${SERVICENAME}.$action" $* "${SERVICENAME}.$action" $*
echo "INFO: $0 $action $* [$SERVICENAME] final returncode rc=$rc" echo "__DB__$SERVICENAME INFO: $0 $action $* [$SERVICENAME] final returncode rc=$rc"
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
# 2016-11-10 ah,ds v1.0 # 2016-11-10 ah,ds v1.0
# 2017-03-29 ..... v1.1 added restore # 2017-03-29 ..... v1.1 added restore
# 2022-01-20 v1.2 fixes with shellcheck # 2022-01-20 v1.2 fixes with shellcheck
# 2022-03-17 v1.3 WIP: add lines with prefix __DB__
# ================================================================================ # ================================================================================
if [ -z "$BACKUP_TARGETDIR" ]; then if [ -z "$BACKUP_TARGETDIR" ]; then
...@@ -23,6 +24,7 @@ fi ...@@ -23,6 +24,7 @@ fi
# CONFIG # CONFIG
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
SERVICEFOUND=0
# unix user of postgres database # unix user of postgres database
PGUSER=postgres PGUSER=postgres
...@@ -31,6 +33,15 @@ fi ...@@ -31,6 +33,15 @@ fi
# FUNCTION # 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(){ function doPgsqlBackup(){
create_targetdir create_targetdir
...@@ -49,16 +60,19 @@ function doPgsqlBackup(){ ...@@ -49,16 +60,19 @@ function doPgsqlBackup(){
su ${PGUSER} -c "pg_dump -Fp ${DATABASE} >$OUTFILE" su ${PGUSER} -c "pg_dump -Fp ${DATABASE} >$OUTFILE"
fetchrc fetchrc
if [ $myrc -eq 0 ]; then db._compressDumpfile "$OUTFILE"
echo -n "compress ... "
compress_file "$OUTFILE" # if [ $myrc -eq 0 ]; then
else # echo -n "compress ... "
color error # compress_file "$OUTFILE"
echo "ERROR occured - no gzip" # else
color reset # color error
# mv $OUTFILE $OUTFILE # echo "ERROR occured - no gzip"
fi # color reset
ls -l "$OUTFILE"* # # mv $OUTFILE $OUTFILE
# echo "__DB__$SERVICENAME INFO: backed up ${DATABASE}"
# fi
# ls -l "$OUTFILE"*
echo echo
done done
} }
...@@ -110,23 +124,33 @@ function restoreByFile(){ ...@@ -110,23 +124,33 @@ function restoreByFile(){
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
# ----- requirements # ----- requirements
j_requireBinary "pg_dump" 1
j_requireProcess "postgres|postmaster" 1
if [ $rc -ne 0 ]; then checkRequirements >/dev/null 2>&1
rc=0 if [ $SERVICEFOUND -eq 0 ]; then
echo "SKIP: postgres seems not to be here" echo "__DB__$SERVICENAME INFO: service [$SERVICENAME] is not avilable on this machine."
else
if [ "$1" = "restore" ]; then
shift 1
restoreByFile $*
else
doPgsqlBackup
fi fi
fi 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 "$0 $* [postgres] final returncode rc=$rc" echo "__DB__$SERVICENAME INFO: $0 $* [$SERVICENAME] final returncode rc=$rc"
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
# #
# 2018-02-02 ah,ds v1.0 first lines # 2018-02-02 ah,ds v1.0 first lines
# 2018-02-09 ah,ds v1.1 write a .meta file after successful backup # 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 if [ -z "$BACKUP_TARGETDIR" ]; then
echo ERROR: you cannot start `basename $0` directly echo "ERROR: you cannot start $(basename $0) directly"
rc=$rc+1 rc=$rc+1
exit 1 exit 1
fi fi
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
# CONFIG # CONFIG
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -34,37 +34,39 @@ function doSqliteBackup(){ ...@@ -34,37 +34,39 @@ function doSqliteBackup(){
create_targetdir create_targetdir
for DATABASE_FILE in `_j_getvar ${FILEDEFS} "sqlite"` for DATABASE_FILE in $(_j_getvar ${FILEDEFS} "sqlite")
do do
echo --- database $DATABASE_FILE echo "--- database $DATABASE_FILE"
if [ ! -f $DATABASE_FILE ]; then if [ ! -f "$DATABASE_FILE" ]; then
color error color error
echo ERROR: given database file does not exist: $DATABASE_FILE echo "ERROR: given database file does not exist: $DATABASE_FILE"
color reset color reset
rc=$rc+1 rc=$rc+1
else 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 if [ $? -ne 0 ]; then
color error 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 color reset
rc=$rc+1 rc=$rc+1
else else
TARGET=`get_outfile ${DATABASE_FILE}` TARGET=$(get_outfile ${DATABASE_FILE})
TARGET=${BACKUP_TARGETDIR}/`echo ${TARGET} | sed "s#/#_#g"`.sql TARGET=${BACKUP_TARGETDIR}/$(echo ${TARGET} | sed "s#/#_#g").sql
META=${TARGET}.gz.meta META=${TARGET}.gz.meta
echo target: $TARGET echo target: $TARGET
sqlite3 $DATABASE_FILE .dump >${TARGET} sqlite3 "$DATABASE_FILE" .dump >"${TARGET}"
fetchrc fetchrc
db._compressDumpfile "${TARGET}"
# $myrc is last returncode - set in fetchrc # $myrc is last returncode - set in fetchrc
if [ $myrc -eq 0 ]; then # if [ $myrc -eq 0 ]; then
echo -n "gzip ... " # echo -n "gzip ... "
compress_file ${TARGET} # compress_file "${TARGET}"
echo $DATABASE_FILE >${META} # echo "$DATABASE_FILE" >"${META}"
else # else
echo "ERROR occured - no gzip" # echo "ERROR occured - no gzip"
fi # fi
ls -l ${TARGET}* # ls -l ${TARGET}*
fi fi
fi fi
...@@ -110,7 +112,7 @@ function restoreByFile(){ ...@@ -110,7 +112,7 @@ function restoreByFile(){
# ----- check requirements # ----- check requirements
j_requireBinary "sqlite3" 1 j_requireBinary "sqlite3" 1
if [ ! -f $FILEDEFS ]; then if [ ! -f "$FILEDEFS" ]; then
echo "INFO: file definitions $FILEDEFS do not exist." echo "INFO: file definitions $FILEDEFS do not exist."
rc=$rc+1 rc=$rc+1
fi fi
...@@ -130,6 +132,6 @@ else ...@@ -130,6 +132,6 @@ else
fi fi
fi fi
echo $0 $* [sqlite] final returncode rc=$rc echo "__DB__$SERVICENAME INFO: $0 $* [$SERVICENAME] final returncode rc=$rc"
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment