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
No related branches found
No related tags found
1 merge request!61Couchdb dump security
......@@ -18,6 +18,7 @@
# 2022-01-20 v1.3 fixes with shellcheck
# 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-14 v1.6 backup security infos (no restore yet)
# ================================================================================
if [ -z "$BACKUP_TARGETDIR" ]; then
......@@ -142,8 +143,9 @@ function doBackup(){
function _doBackupOfSingleInstance(){
create_targetdir
mkdir -p "${BACKUP_TARGETDIR}/${COUCHDB_INSTANCE}" 2>/dev/null
mkdir -p "${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/seq" 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}/security" 2>/dev/null
local ARCHIVE_DIR2="${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/deleted_databases"
test -d "${ARCHIVE_DIR2}" || mkdir -p "${ARCHIVE_DIR2}" 2>/dev/null
......@@ -188,6 +190,7 @@ function _doBackupOfSingleInstance(){
OUTFILE=${BACKUP_TARGETDIR}/${COUCHDB_INSTANCE}/$(get_outfile "${dbname}").couchdbdump
ARCHIVFILE=${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/${dbname}.couchdbdump.gz
SEQFILE=${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/seq/__seq__${dbname}
SECURITYFILE=${ARCHIVE_DIR}/${COUCHDB_INSTANCE}/security/__security__${dbname}.json
sSequenceCurrent=$(_getDbSeq "${dbname}")
sSequenceLast=$(cat "${SEQFILE}" 2>/dev/null | cut -f 1 -d '-')
......@@ -197,7 +200,14 @@ function _doBackupOfSingleInstance(){
# echo "update_seq --+-- current [${sSequenceCurrent}]"
# echo " +-- backup [${sSequenceLast}]"
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
echo
echo "update_seq --+-- current [${sSequenceCurrent}]"
......@@ -213,8 +223,10 @@ function _doBackupOfSingleInstance(){
fetchrc
if [ $myrc -eq 0 ]; then
iDbCount+=1
cp "${OUTFILE}"* "${ARCHIVFILE}" && echo "${sSequenceCurrent}">"${SEQFILE}"
ls -l "${ARCHIVFILE}" "${SEQFILE}"
cp "${OUTFILE}"* "${ARCHIVFILE}" \
&& echo "${sSequenceCurrent}">"${SEQFILE}" \
&& _couchapi GET "${dbname}/_security" > "${SECURITYFILE}"
ls -l "${ARCHIVFILE}" "${SEQFILE}" "${SECURITYFILE}"
fi
else
echo "ERROR occured while dumping - abort"
......@@ -295,6 +307,15 @@ function restoreByFile(){
zcat ${sMyfile} | couchrestore --db $sMyDb
fetchrc
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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment