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

backup security infos (no restore yet)

parent e5230a6d
Branches
No related tags found
1 merge request!61Couchdb dump security
This commit is part of merge request !61. Comments created here will be created in the context of that merge request.
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
# 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__ # 2022-03-17 v1.4 WIP: add lines with prefix __DB__
# 2022-04-07 v1.5 check archive file, not only seq file # 2022-04-07 v1.5 check archive file, not only seq file
# 2022-04-14 v1.6 backup security infos (no restore yet)
# ================================================================================ # ================================================================================
if [ -z "$BACKUP_TARGETDIR" ]; then if [ -z "$BACKUP_TARGETDIR" ]; then
...@@ -144,6 +145,7 @@ function _doBackupOfSingleInstance(){ ...@@ -144,6 +145,7 @@ function _doBackupOfSingleInstance(){
create_targetdir create_targetdir
mkdir -p "${BACKUP_TARGETDIR}/${COUCHDB_INSTANCE}" 2>/dev/null mkdir -p "${BACKUP_TARGETDIR}/${COUCHDB_INSTANCE}" 2>/dev/null
mkdir -p "${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/seq" 2>/dev/null mkdir -p "${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/seq" 2>/dev/null
mkdir -p "${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/security" 2>/dev/null
local ARCHIVE_DIR2="${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/deleted_databases" local ARCHIVE_DIR2="${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/deleted_databases"
test -d "${ARCHIVE_DIR2}" || mkdir -p "${ARCHIVE_DIR2}" 2>/dev/null test -d "${ARCHIVE_DIR2}" || mkdir -p "${ARCHIVE_DIR2}" 2>/dev/null
...@@ -188,6 +190,7 @@ function _doBackupOfSingleInstance(){ ...@@ -188,6 +190,7 @@ function _doBackupOfSingleInstance(){
OUTFILE=${BACKUP_TARGETDIR}/${COUCHDB_INSTANCE}/$(get_outfile "${dbname}").couchdbdump OUTFILE=${BACKUP_TARGETDIR}/${COUCHDB_INSTANCE}/$(get_outfile "${dbname}").couchdbdump
ARCHIVFILE=${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/${dbname}.couchdbdump.gz ARCHIVFILE=${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/${dbname}.couchdbdump.gz
SEQFILE=${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/seq/__seq__${dbname} SEQFILE=${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/seq/__seq__${dbname}
SECURITYFILE=${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/security/__security__${dbname}.json
sSequenceCurrent=$(_getDbSeq "${dbname}") sSequenceCurrent=$(_getDbSeq "${dbname}")
sSequenceLast=$(cat "${SEQFILE}" 2>/dev/null | cut -f 1 -d '-') sSequenceLast=$(cat "${SEQFILE}" 2>/dev/null | cut -f 1 -d '-')
...@@ -197,7 +200,14 @@ function _doBackupOfSingleInstance(){ ...@@ -197,7 +200,14 @@ function _doBackupOfSingleInstance(){
# echo "update_seq --+-- current [${sSequenceCurrent}]" # echo "update_seq --+-- current [${sSequenceCurrent}]"
# echo " +-- backup [${sSequenceLast}]" # echo " +-- backup [${sSequenceLast}]"
if [ "${sSequenceCurrent}" = "${sSequenceLast}" ] && [ -f "$ARCHIVFILE" ]; then if [ "${sSequenceCurrent}" = "${sSequenceLast}" ] && [ -f "$ARCHIVFILE" ]; then
echo SKIP: still on sequence "${sSequenceLast}" echo "SKIP: still on sequence ${sSequenceLast}"
# add security file for already existing databases
test -f "${SECURITYFILE}" || (
echo "INFO: creating missing security file ${SECURITYFILE}"
_couchapi GET "${dbname}/_security" > "${SECURITYFILE}"
)
else else
echo echo
echo "update_seq --+-- current [${sSequenceCurrent}]" echo "update_seq --+-- current [${sSequenceCurrent}]"
...@@ -213,8 +223,10 @@ function _doBackupOfSingleInstance(){ ...@@ -213,8 +223,10 @@ function _doBackupOfSingleInstance(){
fetchrc fetchrc
if [ $myrc -eq 0 ]; then if [ $myrc -eq 0 ]; then
iDbCount+=1 iDbCount+=1
cp "${OUTFILE}"* "${ARCHIVFILE}" && echo "${sSequenceCurrent}">"${SEQFILE}" cp "${OUTFILE}"* "${ARCHIVFILE}" \
ls -l "${ARCHIVFILE}" "${SEQFILE}" && echo "${sSequenceCurrent}">"${SEQFILE}" \
&& _couchapi GET "${dbname}/_security" > "${SECURITYFILE}"
ls -l "${ARCHIVFILE}" "${SEQFILE}" "${SECURITYFILE}"
fi fi
else else
echo "ERROR occured while dumping - abort" echo "ERROR occured while dumping - abort"
...@@ -295,6 +307,15 @@ function restoreByFile(){ ...@@ -295,6 +307,15 @@ function restoreByFile(){
zcat ${sMyfile} | couchrestore --db $sMyDb zcat ${sMyfile} | couchrestore --db $sMyDb
fetchrc fetchrc
color reset color reset
h2 add security infos ...
SECURITYFILE=${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/security/__security__$sMyDb.json
color cmd
cat "$SECURITYFILE"
echo "TODO: import this to $sMyDb."
fetchrc
color reset
echo echo
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment