mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-22 13:44:08 +01:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb5347afe5 | ||
|
|
ca03c5369d | ||
|
|
3008d9125f | ||
|
|
19cf3d007f | ||
|
|
0bbf142349 | ||
|
|
1bc357866f | ||
|
|
b38ad7a5cc | ||
|
|
8bc02ee6c8 | ||
|
|
3e71c377c6 | ||
|
|
76a857239f | ||
|
|
02880d6541 | ||
|
|
564613f329 | ||
|
|
2606d3c4d5 |
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,3 +1,26 @@
|
|||||||
|
## 2.2.2 2020-09-22 <tpansino@github>
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Patch for 2.2.0 release fixing Docker Secrets Support. Was skipping password check.
|
||||||
|
|
||||||
|
## 2.2.1 2020-09-17 <alwynpan@github>
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Ondemand/Manual backup with `backup-now` was throwing errors not being able to find a proper date
|
||||||
|
|
||||||
|
## 2.2.0 2020-09-14 <alwynpan@github>
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Allow to use MariaDB and MongoDBs with no username and password while still allowing Docker Secrets
|
||||||
|
- Changed source of Alpine package repositories
|
||||||
|
|
||||||
|
|
||||||
|
## 2.1.1 2020-09-01 <zicklag@github>
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Add eval to POST_SCRIPT execution
|
||||||
|
|
||||||
|
|
||||||
## 2.1.0 2020-08-29 <dave at tiredofit dot ca>
|
## 2.1.0 2020-08-29 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
10
Dockerfile
10
Dockerfile
@@ -9,7 +9,7 @@ ENV ENABLE_CRON=FALSE \
|
|||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
RUN set -ex && \
|
RUN set -ex && \
|
||||||
echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
|
echo "@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
|
||||||
apk update && \
|
apk update && \
|
||||||
apk upgrade && \
|
apk upgrade && \
|
||||||
apk add -t .db-backup-build-deps \
|
apk add -t .db-backup-build-deps \
|
||||||
@@ -19,7 +19,7 @@ RUN set -ex && \
|
|||||||
xz-dev \
|
xz-dev \
|
||||||
&& \
|
&& \
|
||||||
\
|
\
|
||||||
apk add -t .db-backup-run-deps \
|
apk add --no-cache -t .db-backup-run-deps \
|
||||||
bzip2 \
|
bzip2 \
|
||||||
influxdb \
|
influxdb \
|
||||||
mariadb-client \
|
mariadb-client \
|
||||||
@@ -33,9 +33,9 @@ RUN set -ex && \
|
|||||||
zstd \
|
zstd \
|
||||||
&& \
|
&& \
|
||||||
\
|
\
|
||||||
apk add \
|
apk add --no-cache \
|
||||||
pixz@testing \
|
pixz@testing \
|
||||||
&& \
|
&& \
|
||||||
\
|
\
|
||||||
mkdir -p /usr/src/pbzip2 && \
|
mkdir -p /usr/src/pbzip2 && \
|
||||||
curl -ssL https://launchpad.net/pbzip2/1.1/1.1.13/+download/pbzip2-1.1.13.tar.gz | tar xvfz - --strip=1 -C /usr/src/pbzip2 && \
|
curl -ssL https://launchpad.net/pbzip2/1.1/1.1.13/+download/pbzip2-1.1.13.tar.gz | tar xvfz - --strip=1 -C /usr/src/pbzip2 && \
|
||||||
|
|||||||
47
README.md
47
README.md
@@ -32,28 +32,29 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
|
|||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
- [Introduction](#introduction)
|
- [hub.docker.com/r/tiredofit/db-backup](#hubdockercomrtiredofitdb-backup)
|
||||||
- [Authors](#authors)
|
- [Introduction](#introduction)
|
||||||
- [Table of Contents](#table-of-contents)
|
- [Authors](#authors)
|
||||||
- [Prerequisites](#prerequisites)
|
- [Table of Contents](#table-of-contents)
|
||||||
- [Installation](#installation)
|
- [Prerequisites](#prerequisites)
|
||||||
- [Quick Start](#quick-start)
|
- [Installation](#installation)
|
||||||
- [Configuration](#configuration)
|
- [Quick Start](#quick-start)
|
||||||
- [Data-Volumes](#data-volumes)
|
- [Configuration](#configuration)
|
||||||
- [Environment Variables](#environment-variables)
|
- [Data-Volumes](#data-volumes)
|
||||||
- [Maintenance](#maintenance)
|
- [Environment Variables](#environment-variables)
|
||||||
- [Shell Access](#shell-access)
|
- [Maintenance](#maintenance)
|
||||||
- [Custom Scripts](#custom-scripts)
|
- [Shell Access](#shell-access)
|
||||||
- [Example Post Script](#example-post-script)
|
- [Custom Scripts](#custom-scripts)
|
||||||
- [$1=EXIT_CODE (After running backup routine)](#1exit_code-after-running-backup-routine)
|
- [Example Post Script](#example-post-script)
|
||||||
- [$2=DB_TYPE (Type of Backup)](#2db_type-type-of-backup)
|
- [$1=EXIT_CODE (After running backup routine)](#1exit_code-after-running-backup-routine)
|
||||||
- [$3=DB_HOST (Backup Host)](#3db_host-backup-host)
|
- [$2=DB_TYPE (Type of Backup)](#2db_type-type-of-backup)
|
||||||
- [#4=DB_NAME (Name of Database backed up](#4db_name-name-of-database-backed-up)
|
- [$3=DB_HOST (Backup Host)](#3db_host-backup-host)
|
||||||
- [$5=DATE (Date of Backup)](#5date-date-of-backup)
|
- [#4=DB_NAME (Name of Database backed up](#4db_name-name-of-database-backed-up)
|
||||||
- [$6=TIME (Time of Backup)](#6time-time-of-backup)
|
- [$5=DATE (Date of Backup)](#5date-date-of-backup)
|
||||||
- [$7=BACKUP_FILENAME (Filename of Backup)](#7backup_filename-filename-of-backup)
|
- [$6=TIME (Time of Backup)](#6time-time-of-backup)
|
||||||
- [$8=FILESIZE (Filesize of backup)](#8filesize-filesize-of-backup)
|
- [$7=BACKUP_FILENAME (Filename of Backup)](#7backup_filename-filename-of-backup)
|
||||||
- [$9=MD5_RESULT (MD5Sum if enabled)](#9md5_result-md5sum-if-enabled)
|
- [$8=FILESIZE (Filesize of backup)](#8filesize-filesize-of-backup)
|
||||||
|
- [$9=MD5_RESULT (MD5Sum if enabled)](#9md5_result-md5sum-if-enabled)
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
@@ -90,8 +91,6 @@ The following directories are used for configuration and can be mapped for persi
|
|||||||
|
|
||||||
### Environment Variables
|
### Environment Variables
|
||||||
|
|
||||||
*If you are trying to backup a database that doesn't have a user or a password (you should!) make sure you set `CONTAINER_ENABLE_DOCKER_SECRETS=FALSE`*
|
|
||||||
|
|
||||||
Along with the Environment Variables from the [Base image](https://hub.docker.com/r/tiredofit/alpine), below is the complete list of available options that can be used to customize your installation.
|
Along with the Environment Variables from the [Base image](https://hub.docker.com/r/tiredofit/alpine), below is the complete list of available options that can be used to customize your installation.
|
||||||
|
|
||||||
| Parameter | Description |
|
| Parameter | Description |
|
||||||
|
|||||||
@@ -14,8 +14,44 @@ fi
|
|||||||
sanity_var DB_TYPE "Database Type"
|
sanity_var DB_TYPE "Database Type"
|
||||||
sanity_var DB_HOST "Database Host"
|
sanity_var DB_HOST "Database Host"
|
||||||
|
|
||||||
file_env 'DB_USER'
|
### Set the Database Type
|
||||||
file_env 'DB_PASS'
|
dbtype=${DB_TYPE}
|
||||||
|
|
||||||
|
case "$dbtype" in
|
||||||
|
"couch" | "couchdb" | "COUCH" | "COUCHDB" )
|
||||||
|
dbtype=couch
|
||||||
|
dbport=${DB_PORT:-5984}
|
||||||
|
file_env 'DB_USER'
|
||||||
|
file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
"influx" | "influxdb" | "INFLUX" | "INFLUXDB" )
|
||||||
|
dbtype=influx
|
||||||
|
dbport=${DB_PORT:-8088}
|
||||||
|
file_env 'DB_USER'
|
||||||
|
file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
"mongo" | "mongodb" | "MONGO" | "MONGODB" )
|
||||||
|
dbtype=mongo
|
||||||
|
dbport=${DB_PORT:-27017}
|
||||||
|
[[ ( -n "${DB_USER}" ) || ( -n "${DB_USER_FILE}" ) ]] && file_env 'DB_USER'
|
||||||
|
[[ ( -n "${DB_PASS}" ) || ( -n "${DB_PASS_FILE}" ) ]] && file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
"mysql" | "MYSQL" | "mariadb" | "MARIADB")
|
||||||
|
dbtype=mysql
|
||||||
|
dbport=${DB_PORT:-3306}
|
||||||
|
[[ ( -n "${DB_PASS}" ) || ( -n "${DB_PASS_FILE}" ) ]] && file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
"postgres" | "postgresql" | "pgsql" | "POSTGRES" | "POSTGRESQL" | "PGSQL" )
|
||||||
|
dbtype=pgsql
|
||||||
|
dbport=${DB_PORT:-5432}
|
||||||
|
[[ ( -n "${DB_PASS}" ) || ( -n "${DB_PASS_FILE}" ) ]] && file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
"redis" | "REDIS" )
|
||||||
|
dbtype=redis
|
||||||
|
dbport=${DB_PORT:-6379}
|
||||||
|
[[ ( -n "${DB_PASS}" || ( -n "${DB_PASS_FILE}" ) ) ]] && file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
### Set Defaults
|
### Set Defaults
|
||||||
BACKUP_LOCATION=${BACKUP_LOCATION:-"FILESYSTEM"}
|
BACKUP_LOCATION=${BACKUP_LOCATION:-"FILESYSTEM"}
|
||||||
@@ -27,7 +63,6 @@ DB_DUMP_TARGET=${DB_DUMP_TARGET:-/backup}
|
|||||||
dbhost=${DB_HOST}
|
dbhost=${DB_HOST}
|
||||||
dbname=${DB_NAME}
|
dbname=${DB_NAME}
|
||||||
dbpass=${DB_PASS}
|
dbpass=${DB_PASS}
|
||||||
dbtype=${DB_TYPE}
|
|
||||||
dbuser=${DB_USER}
|
dbuser=${DB_USER}
|
||||||
MD5=${MD5:-TRUE}
|
MD5=${MD5:-TRUE}
|
||||||
PARALLEL_COMPRESSION=${PARALLEL_COMPRESSION:-TRUE}
|
PARALLEL_COMPRESSION=${PARALLEL_COMPRESSION:-TRUE}
|
||||||
@@ -65,39 +100,23 @@ else
|
|||||||
zstd="zstd --rm -${COMPRESSION_LEVEL}"
|
zstd="zstd --rm -${COMPRESSION_LEVEL}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### Set the Database Type
|
### Set the Database Authentication Details
|
||||||
case "$dbtype" in
|
case "$dbtype" in
|
||||||
"couch" | "couchdb" | "COUCH" | "COUCHDB" )
|
"mongo" )
|
||||||
dbtype=couch
|
[[ ( -n "${DB_USER}" ) ]] && MONGO_USER_STR=" --username ${dbuser}"
|
||||||
dbport=${DB_PORT:-5984}
|
[[ ( -n "${DB_PASS}" ) ]] && MONGO_PASS_STR=" --password ${dbpass}"
|
||||||
;;
|
[[ ( -n "${DB_NAME}" ) ]] && MONGO_DB_STR=" --db ${dbname}"
|
||||||
"influx" | "influxdb" | "INFLUX" | "INFLUXDB" )
|
;;
|
||||||
dbtype=influx
|
"mysql" )
|
||||||
dbport=${DB_PORT:-8088}
|
[[ ( -n "${DB_PASS}" ) ]] && export MYSQL_PWD=${dbpass}
|
||||||
;;
|
;;
|
||||||
"mongo" | "mongodb" | "MONGO" | "MONGODB" )
|
"postgres" )
|
||||||
dbtype=mongo
|
[[ ( -n "${DB_PASS}" ) ]] && POSTGRES_PASS_STR="PGPASSWORD=${dbpass}"
|
||||||
dbport=${DB_PORT:-27017}
|
;;
|
||||||
[[ ( -n "${DB_USER}" ) ]] && MONGO_USER_STR=" --username ${dbuser}"
|
"redis" )
|
||||||
[[ ( -n "${DB_PASS}" ) ]] && MONGO_PASS_STR=" --password ${dbpass}"
|
[[ ( -n "${DB_PASS}" ) ]] && REDIS_PASS_STR=" -a ${dbpass}"
|
||||||
[[ ( -n "${DB_NAME}" ) ]] && MONGO_DB_STR=" --db ${dbname}"
|
;;
|
||||||
;;
|
esac
|
||||||
"mysql" | "MYSQL" | "mariadb" | "MARIADB")
|
|
||||||
dbtype=mysql
|
|
||||||
dbport=${DB_PORT:-3306}
|
|
||||||
[[ ( -n "${DB_PASS}" ) ]] && export MYSQL_PWD=${dbpass}
|
|
||||||
;;
|
|
||||||
"postgres" | "postgresql" | "pgsql" | "POSTGRES" | "POSTGRESQL" | "PGSQL" )
|
|
||||||
dbtype=pgsql
|
|
||||||
dbport=${DB_PORT:-5432}
|
|
||||||
[[ ( -n "${DB_PASS}" ) ]] && POSTGRES_PASS_STR="PGPASSWORD=${dbpass}"
|
|
||||||
;;
|
|
||||||
"redis" | "REDIS" )
|
|
||||||
dbtype=redis
|
|
||||||
dbport=${DB_PORT:-6379}
|
|
||||||
[[ ( -n "${DB_PASS}" ) ]] && REDIS_PASS_STR=" -a ${dbpass}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
### Functions
|
### Functions
|
||||||
backup_couch() {
|
backup_couch() {
|
||||||
@@ -375,21 +394,23 @@ move_backup() {
|
|||||||
print_debug "Backup routines Initialized on $(date)"
|
print_debug "Backup routines Initialized on $(date)"
|
||||||
|
|
||||||
### Wait for Next time to start backup
|
### Wait for Next time to start backup
|
||||||
current_time=$(date +"%s")
|
if [ "$1" != "NOW" ]; then
|
||||||
today=$(date +"%Y%m%d")
|
current_time=$(date +"%s")
|
||||||
|
today=$(date +"%Y%m%d")
|
||||||
|
|
||||||
if [[ $DB_DUMP_BEGIN =~ ^\+(.*)$ ]]; then
|
if [[ $DB_DUMP_BEGIN =~ ^\+(.*)$ ]]; then
|
||||||
waittime=$(( ${BASH_REMATCH[1]} * 60 ))
|
waittime=$(( ${BASH_REMATCH[1]} * 60 ))
|
||||||
else
|
else
|
||||||
target_time=$(date --date="${today}${DB_DUMP_BEGIN}" +"%s")
|
target_time=$(date --date="${today}${DB_DUMP_BEGIN}" +"%s")
|
||||||
if [[ "$target_time" < "$current_time" ]]; then
|
if [[ "$target_time" < "$current_time" ]]; then
|
||||||
target_time=$(($target_time + 24*60*60))
|
target_time=$(($target_time + 24*60*60))
|
||||||
|
fi
|
||||||
|
waittime=$(($target_time - $current_time))
|
||||||
fi
|
fi
|
||||||
waittime=$(($target_time - $current_time))
|
|
||||||
fi
|
|
||||||
|
|
||||||
print_notice "Next Backup at $(date -d @${target_time} +"%Y-%m-%d %T %Z")"
|
print_notice "Next Backup at $(date -d @${target_time} +"%Y-%m-%d %T %Z")"
|
||||||
sleep $waittime
|
sleep $waittime
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
### Commence Backup
|
### Commence Backup
|
||||||
@@ -446,7 +467,7 @@ print_debug "Backup routines Initialized on $(date)"
|
|||||||
|
|
||||||
if [ -n "$POST_SCRIPT" ] ; then
|
if [ -n "$POST_SCRIPT" ] ; then
|
||||||
print_notice "Found POST_SCRIPT environment variable. Executing"
|
print_notice "Found POST_SCRIPT environment variable. Executing"
|
||||||
"${POST_SCRIPT}"
|
eval "${POST_SCRIPT}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### Post Backup Custom Script Support
|
### Post Backup Custom Script Support
|
||||||
|
|||||||
Reference in New Issue
Block a user