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

set prefix __DB__ in backup

parent c35505ef
No related branches found
No related tags found
1 merge request!48set prefix __DB__ in backup
......@@ -142,7 +142,7 @@ function _doBackupOfSingleInstance(){
for dbname in $(_getDblist)
do
echo "----- $(date) ${COUCHDB_INSTANCE} -- ${dbname}"
echo -n "__DB__${SERVICENAME} ${COUCHDB_INSTANCE} $_dbname backup "
OUTFILE=${BACKUP_TARGETDIR}/${COUCHDB_INSTANCE}/$(get_outfile "${dbname}").couchdbdump
python ${dirPythonPackages}/couchdb/tools/dump.py "${COUCHDB_URL}/${dbname}" >"${OUTFILE}"
......
......@@ -158,8 +158,7 @@ function mysql.backup(){
for _dbname in $( mysql.db.list )
do
echo "--- database $_dbname"
echo -n "backup ... "
echo -n "__DB__${SERVICENAME} $_dbname backup "
_outfile="${BACKUP_TARGETDIR}/$(get_outfile ${_dbname}).sql"
mysql.db.dump "$_dbname" "$_outfile"
......
#!/bin/bash
# ================================================================================
#
# LOCALDUMP :: NEW SERVICE
#
# ================================================================================
if [ -z "$BACKUP_TARGETDIR" ]; then
echo "ERROR: you cannot start $(basename $0) directly"
rc=$rc+1
exit 1
fi
# --------------------------------------------------------------------------------
# CONFIG
# --------------------------------------------------------------------------------
SERVICEFOUND=0
# --------------------------------------------------------------------------------
# FUNCTIONS
# --------------------------------------------------------------------------------
function checkRequirements(){
j_requireBinary "client" 1
j_requireBinary "dumper" 1
j_requireProcess "service1|service2" 1
if [ ! -d $SOURCE_DIR ]; then
echo "INFO: directory $SOURCE_DIR doees not exist."
rc=$rc+1
fi
# set flag and reset return code
test $rc -eq 0 && SERVICEFOUND=1
rc=0
}
# detect and backup all databases of the service
function doBackup(){
create_targetdir
for DATABASE_DIR in __DATABASE_LIST__
do
DUMPCOMMAND [params] "$DATABASE" > "$OUTFILE"
fetchrc
# $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
done
}
# restore database dump file into database
# param string database dump file (gzipped)
# param string optional: database to import; default: database is parsed from file
function restoreByFile(){
sMyfile=$1
sMyDb=$2
if [ -z "$sMyDb" ]; then
h2 "analyze dump $sMyfile"
sMyDb=$(guessDB $sMyfile)
echo "detected db schema from file: [${sMyDb}]"
else
echo "db schema from param 2: [${sMyDb}]"
fi
echo
echo import to "$sMyDb"...
h2 ensure that database exists ...
color cmd
echo "CREATE DATABASE IF NOT EXISTS ${sMyDb};" | mysql
color reset
h2 import ...
ls -l "$sMyfile"
echo "import to database [${sMyDb}]"
color cmd
zcat "$sMyfile" | mysql "${sMyDb}"
fetchrc
color reset
}
# --------------------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------------------
# ----- set action
checkRequirements >/dev/null 2>&1
if [ $SERVICEFOUND -eq 0 ]; then
echo "INFO: service [$SERVICENAME] is not avilable on this machine."
fi
case $1 in
check)
# repeat check ... but show output
echo
echo Details:
checkRequirements
echo
;;
backup)
test $SERVICEFOUND -eq 1 && doBackup
;;
restore)
shift 1
test $SERVICEFOUND -eq 1 && restoreByFile $*
;;
*)
echo ERROR: wrong syntax:
echo $0 $*
exit 1
esac
echo "INFO: $0 $* [$SERVICENAME] final returncode rc=$rc"
# --------------------------------------------------------------------------------
......@@ -54,8 +54,7 @@ function doPgsqlBackup(){
sSqlGetDblist="select datname from pg_database where not datistemplate and datallowconn order by datname;"
for DATABASE in $(su ${PGUSER} -c "psql -At -c '$sSqlGetDblist' postgres" 2>/dev/null)
do
echo "----- $DATABASE"
echo -n "backup ... "
echo -n "__DB__${SERVICENAME} $_dbname backup "
OUTFILE="${BACKUP_TARGETDIR}/$(get_outfile ${DATABASE}).sql"
su ${PGUSER} -c "pg_dump -Fp ${DATABASE} >$OUTFILE"
fetchrc
......
......@@ -24,3 +24,15 @@ dir-localdumps configures the target base directory for dumps. Below are subdire
In those are the dumps containing name of database scheme and a timestamp. All dumps are gzip compressed.
keep-days contains an integer for the days to keep database dumps locally. Older dumps will be removed.
## Global vars in plugin scripts
```
BACKUP_BASEDIR {string} base directory for db dumps
BACKUP_DATE {string} string with current timestamp; will be part of filename for backups
BACKUP_KEEP_DAYS {int} count of days how long to keep db dumps below $BACKUP_BASEDIR
BACKUP_PLUGINDIR {string} scripts for supported databases; [APP]/plugins/localdump
BACKUP_SCRIPT {string} script name of db service
BACKUP_TARGETDIR {string} target directory db dumps of current service; eg. /var/backup/mysql/
SERVICENAME {string} name of db service (one of mysql|pgsql|...)
```
\ No newline at end of file
......@@ -36,7 +36,7 @@ function doSqliteBackup(){
for DATABASE_FILE in $(_j_getvar ${FILEDEFS} "sqlite")
do
echo "--- database $DATABASE_FILE"
echo -n "__DB__${SERVICENAME} $_dbname backup "
if [ ! -f "$DATABASE_FILE" ]; then
color error
echo "ERROR: given database file does not exist: $DATABASE_FILE"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment