Compare commits

...

12 Commits

Author SHA1 Message Date
Dave Conroy
789a9e5f5a Release 2.11.2 - See CHANGELOG.md 2022-02-09 17:14:25 -08:00
Dave Conroy
b80d61f997 Merge pull request #102 from jacksgt/fix-s3-variable
Fix S3 variables (again)
2022-02-08 13:58:33 -08:00
Jack Henschel
9e23def7b4 Fix S3 variables (again)
S3_ENDPOINT is not used anywhere in the code, but S3_HOST.
2022-02-08 21:52:53 +01:00
Dave Conroy
ca31eb840d 2.11.1 - See CHANGELOG.md 2022-02-06 17:03:36 -08:00
Dave Conroy
6bec188633 Merge pull request #101 from jacksgt/add-s3-endpoint
Correct several variables for S3 backups
2022-02-06 17:01:18 -08:00
Dave Conroy
43562077b0 Merge pull request #100 from jacksgt/patch-1
Use exit code 0 when running in manual mode
2022-02-06 16:59:00 -08:00
Jack Henschel
c39bdeebae Correct several variables for S3 backups
* S3_URI_STYLE is not used anywhere (anymore)
* BACKUP_TYPE is not documented anywhere, redundant with BACKUP_LOCATION
* S3_HOST is not used anymore, document S3_ENDPOINT instead

ref 4d6419fd18
2022-02-06 00:50:35 +01:00
Jack Henschel
36b5909483 Use exit code 0 when running in manual mode
When running this container as a Kubernetes cronjob, it is really inconvenient that the script exits with return code "1", thereby marking the job as a failure.
Instead, the script should return "0" because everything was successful.
2022-02-06 00:20:30 +01:00
Dave Conroy
6033b1b0a9 Update README to talk about quoting the values 2022-01-31 13:59:53 -08:00
Dave Conroy
88218915e1 Release 2.11.0 - See CHANGELOG.md 2022-01-20 09:23:06 -08:00
Dave Conroy
065887f789 Release 2.10.3 - See CHANGELOG.md 2022-01-07 06:33:46 -08:00
Dave Conroy
5aba713b73 Release 2.10.2 - See CHANGELOG.md 2021-12-28 14:16:46 -08:00
7 changed files with 137 additions and 113 deletions

View File

@@ -105,6 +105,6 @@ jobs:
builder: ${{ steps.buildx.outputs.name }} builder: ${{ steps.buildx.outputs.name }}
context: . context: .
file: ./Dockerfile file: ./Dockerfile
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true push: true
tags: ${{ steps.prep.outputs.tags }} tags: ${{ steps.prep.outputs.tags }}

View File

@@ -105,6 +105,6 @@ jobs:
builder: ${{ steps.buildx.outputs.name }} builder: ${{ steps.buildx.outputs.name }}
context: . context: .
file: ./Dockerfile file: ./Dockerfile
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true push: true
tags: ${{ steps.prep.outputs.tags }} tags: ${{ steps.prep.outputs.tags }}

View File

@@ -1,3 +1,38 @@
## 2.11.2 2022-02-09 <dave at tiredofit dot ca>
### Changed
- Refresh base image
## 2.11.1 2022-01-20 <jacksgt@github>
### Changed
- Modernized S3 variables and sanity checks
- Change exit code to 0 when executing a manual backup
## 2.11.0 2022-01-20 <dave at tiredofit dot ca>
### Added
- Add capability to select `TEMP_LOCATION` for initial backup and compression before backup completes to avoid filling system memory
### Changed
- Cleanup for MariaDB/MySQL DB ready routines that half worked in 2.10.3
- Code cleanup
## 2.10.3 2022-01-07 <dave at tiredofit dot ca>
### Changed
- Change the way MariaD/MySQL connectivity check is performed to allow for better compatibility without requiring the DB_USER to have PROCESS privileges
## 2.10.2 2021-12-28 <dave at tiredofit dot ca>
### Changed
- Remove logrotate configuration for redis which shouldn't exist in the first place
## 2.10.1 2021-12-22 <milenkara@github> ## 2.10.1 2021-12-22 <milenkara@github>
### Added ### Added

View File

@@ -3,7 +3,9 @@ FROM docker.io/tiredofit/alpine:3.15
### Set Environment Variables ### Set Environment Variables
ENV MSSQL_VERSION=17.8.1.1-1 \ ENV MSSQL_VERSION=17.8.1.1-1 \
CONTAINER_ENABLE_MESSAGING=FALSE \ CONTAINER_ENABLE_MESSAGING=FALSE \
CONTAINER_ENABLE_MONITORING=TRUE CONTAINER_ENABLE_MONITORING=TRUE \
IMAGE_NAME="tiredofit/db-backup" \
IMAGE_REPO_URL="https://github.com/tiredofit/docker-db-backup/"
### Dependencies ### Dependencies
RUN set -ex && \ RUN set -ex && \
@@ -61,6 +63,7 @@ RUN set -ex && \
### Cleanup ### Cleanup
apk del .db-backup-build-deps && \ apk del .db-backup-build-deps && \
rm -rf /usr/src/* && \ rm -rf /usr/src/* && \
rm -rf /etc/logrotate.d/redis && \
rm -rf /root/.cache /tmp/* /var/cache/apk/* rm -rf /root/.cache /tmp/* /var/cache/apk/*
### S6 Setup ### S6 Setup

View File

@@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2021 Dave Conroy Copyright (c) 2022 Dave Conroy
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -31,40 +31,29 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
## Table of Contents ## Table of Contents
- [github.com/tiredofit/docker-db-backup](#githubcomtiredofitdocker-db-backup) - [About](#about)
- [About](#about) - [Maintainer](#maintainer)
- [Maintainer](#maintainer) - [Table of Contents](#table-of-contents)
- [Table of Contents](#table-of-contents) - [Prerequisites and Assumptions](#prerequisites-and-assumptions)
- [Prerequisites and Assumptions](#prerequisites-and-assumptions) - [Installation](#installation)
- [Installation](#installation)
- [Build from Source](#build-from-source) - [Build from Source](#build-from-source)
- [Prebuilt Images](#prebuilt-images) - [Prebuilt Images](#prebuilt-images)
- [Configuration](#configuration) - [Configuration](#configuration)
- [Quick Start](#quick-start) - [Quick Start](#quick-start)
- [Persistent Storage](#persistent-storage) - [Persistent Storage](#persistent-storage)
- [Environment Variables](#environment-variables) - [Environment Variables](#environment-variables)
- [Base Images used](#base-images-used) - [Base Images used](#base-images-used)
- [Backing Up to S3 Compatible Services](#backing-up-to-s3-compatible-services) - [Backing Up to S3 Compatible Services](#backing-up-to-s3-compatible-services)
- [Maintenance](#maintenance) - [Maintenance](#maintenance)
- [Shell Access](#shell-access) - [Shell Access](#shell-access)
- [Manual Backups](#manual-backups) - [Manual Backups](#manual-backups)
- [Custom Scripts](#custom-scripts) - [Custom Scripts](#custom-scripts)
- [#### Example Post Script](#-example-post-script) - [Support](#support)
- [#### $1=EXIT_CODE (After running backup routine)](#-1exit_code-after-running-backup-routine)
- [#### $2=DB_TYPE (Type of Backup)](#-2db_type-type-of-backup)
- [#### $3=DB_HOST (Backup Host)](#-3db_host-backup-host)
- [#### #4=DB_NAME (Name of Database backed up](#-4db_name-name-of-database-backed-up)
- [#### $5=DATE (Date of Backup)](#-5date-date-of-backup)
- [#### $6=TIME (Time of Backup)](#--6time-time-of-backup)
- [#### $7=BACKUP_FILENAME (Filename of Backup)](#--7backup_filename-filename-of-backup)
- [#### $8=FILESIZE (Filesize of backup)](#--8filesize-filesize-of-backup)
- [#### $9=MD5_RESULT (MD5Sum if enabled)](#--9md5_result-md5sum-if-enabled)
- [Support](#support)
- [Usage](#usage) - [Usage](#usage)
- [Bugfixes](#bugfixes) - [Bugfixes](#bugfixes)
- [Feature Requests](#feature-requests) - [Feature Requests](#feature-requests)
- [Updates](#updates) - [Updates](#updates)
- [License](#license) - [License](#license)
## Prerequisites and Assumptions ## Prerequisites and Assumptions
@@ -120,31 +109,36 @@ Be sure to view the following repositories to understand all the customizable op
| [OS Base](https://github.com/tiredofit/docker-alpine/) | Customized Image based on Alpine Linux | | [OS Base](https://github.com/tiredofit/docker-alpine/) | Customized Image based on Alpine Linux |
| Parameter | Description | | Parameter | Description | Default |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- |
| `BACKUP_LOCATION` | Backup to `FILESYSTEM` or `S3` compatible services like S3, Minio, Wasabi - Default `FILESYSTEM` | | `BACKUP_LOCATION` | Backup to `FILESYSTEM` or `S3` compatible services like S3, Minio, Wasabi | `FILESYSTEM` |
| `COMPRESSION` | Use either Gzip `GZ`, Bzip2 `BZ`, XZip `XZ`, ZSTD `ZSTD` or none `NONE` - Default `GZ` | | `COMPRESSION` | Use either Gzip `GZ`, Bzip2 `BZ`, XZip `XZ`, ZSTD `ZSTD` or none `NONE` | `GZ` |
| `COMPRESSION_LEVEL` | Numberical value of what level of compression to use, most allow `1` to `9` except for `ZSTD` which allows for `1` to `19` - Default `3` | | `COMPRESSION_LEVEL` | Numberical value of what level of compression to use, most allow `1` to `9` except for `ZSTD` which allows for `1` to `19` - | `3` |
| `DB_AUTH` | (Mongo Only - Optional) Authentication Database | | `DB_AUTH` | (Mongo Only - Optional) Authentication Database | |
| `DB_TYPE` | Type of DB Server to backup `couch` `influx` `mysql` `pgsql` `mongo` `redis` `sqlite3` | | `DB_TYPE` | Type of DB Server to backup `couch` `influx` `mysql` `pgsql` `mongo` `redis` `sqlite3` | |
| `DB_HOST` | Server Hostname e.g. `mariadb`. For `sqlite3`, full path to DB file e.g. `/backup/db.sqlite3` | | `DB_HOST` | Server Hostname e.g. `mariadb`. For `sqlite3`, full path to DB file e.g. `/backup/db.sqlite3` | |
| `DB_NAME` | Schema Name e.g. `database` | | `DB_NAME` | Schema Name e.g. `database` | |
| `DB_USER` | username for the database - use `root` to backup all MySQL of them. | | `DB_USER` | username for the database - use `root` to backup all MySQL of them. | |
| `DB_PASS` | (optional if DB doesn't require it) password for the database | | `DB_PASS` | (optional if DB doesn't require it) password for the database | |
| `DB_PORT` | (optional) Set port to connect to DB_HOST. Defaults are provided | | `DB_PORT` | (optional) Set port to connect to DB_HOST. Defaults are provided | varies |
| `DB_DUMP_FREQ` | How often to do a dump, in minutes. Defaults to 1440 minutes, or once per day. | | `DB_DUMP_FREQ` | How often to do a dump, in minutes. Defaults to 1440 minutes, or once per day. | `1440` |
| `DB_DUMP_BEGIN` | What time to do the first dump. Defaults to immediate. Must be in one of two formats | | `DB_DUMP_BEGIN` | What time to do the first dump. Defaults to immediate. Must be in one of two formats | |
| | Absolute HHMM, e.g. `2330` or `0415` | | | Absolute HHMM, e.g. `2330` or `0415` | |
| | Relative +MM, i.e. how many minutes after starting the container, e.g. `+0` (immediate), `+10` (in 10 minutes), or `+90` in an hour and a half | | | Relative +MM, i.e. how many minutes after starting the container, e.g. `+0` (immediate), `+10` (in 10 minutes), or `+90` in an hour and a half | |
| `DB_CLEANUP_TIME` | Value in minutes to delete old backups (only fired when dump freqency fires). 1440 would delete anything above 1 day old. You don't need to set this variable if you want to hold onto everything. | | `DB_CLEANUP_TIME` | Value in minutes to delete old backups (only fired when dump freqency fires). 1440 would delete anything above 1 day old. You don't need to set this variable if you want to hold onto everything. | `FALSE` |
| `DEBUG_MODE` | If set to `true`, print copious shell script messages to the container log. Otherwise only basic messages are printed. | | `DEBUG_MODE` | If set to `true`, print copious shell script messages to the container log. Otherwise only basic messages are printed. | |
| `EXTRA_OPTS` | If you need to pass extra arguments to the backup command, add them here e.g. "--extra-command" | | `EXTRA_OPTS` | If you need to pass extra arguments to the backup command, add them here e.g. `--extra-command` | |
| `MD5` | Generate MD5 Sum in Directory, `TRUE` or `FALSE` - Default `TRUE` | | `MYSQL_MAX_ALLOWED_PACKET` | Max allowed packet if backing up MySQL / MariaDB | `512M` |
| `PARALLEL_COMPRESSION` | Use multiple cores when compressing backups `TRUE` or `FALSE` - Default `TRUE` | | `MD5` | Generate MD5 Sum in Directory, `TRUE` or `FALSE` | `TRUE` |
| `PARALLEL_COMPRESSION` | Use multiple cores when compressing backups `TRUE` or `FALSE` | `TRUE` |
| `POST_SCRIPT` | Fill this variable in with a command to execute post the script backing up | | | `POST_SCRIPT` | Fill this variable in with a command to execute post the script backing up | |
| `SPLIT_DB` | If using root as username and multiple DBs on system, set to TRUE to create Seperate DB Backups instead of all in one. - Default `FALSE` | | `SPLIT_DB` | If using root as username and multiple DBs on system, set to TRUE to create Seperate DB Backups instead of all in one. | `FALSE` |
| `TEMP_LOCATION` | Perform Backups and Compression in this temporary directory | `/tmp/backups/` |
- When using compression with MongoDB, only `GZ` compression is possible.
- You may need to wrap your `DB_DUMP_BEGIN` value in quotes for it to properly parse. There have been reports of backups that start with a `0` get converted into a different format which will not allow the timer to start at the correct time.
When using compression with MongoDB, only `GZ` compression is possible.
#### Backing Up to S3 Compatible Services #### Backing Up to S3 Compatible Services
@@ -152,13 +146,13 @@ If `BACKUP_LOCATION` = `S3` then the following options are used.
| Parameter | Description | | Parameter | Description |
| --------------- | --------------------------------------------------------------------------------------- | | --------------- | --------------------------------------------------------------------------------------- |
| `S3_BUCKET` | S3 Bucket name e.g. 'mybucket' | | `S3_BUCKET` | S3 Bucket name e.g. `mybucket` |
| `S3_HOST` | Hostname of S3 Server e.g "s3.amazonaws.com" - You can also include a port if necessary |
| `S3_KEY_ID` | S3 Key ID | | `S3_KEY_ID` | S3 Key ID |
| `S3_KEY_SECRET` | S3 Key Secret | | `S3_KEY_SECRET` | S3 Key Secret |
| `S3_PATH` | S3 Pathname to save to e.g. '`backup`' | | `S3_PATH` | S3 Pathname to save to e.g. '`backup`' |
| `S3_PROTOCOL` | Use either `http` or `https` to access service - Default `https` |
| `S3_REGION` | Define region in which bucket is defined. Example: `ap-northeast-2` | | `S3_REGION` | Define region in which bucket is defined. Example: `ap-northeast-2` |
| `S3_HOST` | Hostname (and port) of S3-compatible service, e.g. `minio:8080`. Defaults to AWS. |
| `S3_PROTOCOL` | Protocol to connect to `S3_HOST`. Either `http` or `https`. Defaults to `https`. |
## Maintenance ## Maintenance

View File

@@ -39,6 +39,7 @@ case "$dbtype" in
dbtype=mysql dbtype=mysql
dbport=${DB_PORT:-3306} dbport=${DB_PORT:-3306}
[[ ( -n "${DB_PASS}" ) || ( -n "${DB_PASS_FILE}" ) ]] && file_env 'DB_PASS' [[ ( -n "${DB_PASS}" ) || ( -n "${DB_PASS_FILE}" ) ]] && file_env 'DB_PASS'
MYSQL_MAX_ALLOWED_PACKET=${MYSQL_MAX_ALLOWED_PACKET:-"512M"}
;; ;;
"mssql" | "MSSQL" | "microsoftsql" | "MICROSOFTSQL") "mssql" | "MSSQL" | "microsoftsql" | "MICROSOFTSQL")
apkArch="$(apk --print-arch)"; \ apkArch="$(apk --print-arch)"; \
@@ -66,28 +67,26 @@ esac
### Set Defaults ### Set Defaults
BACKUP_LOCATION=${BACKUP_LOCATION:-"FILESYSTEM"} BACKUP_LOCATION=${BACKUP_LOCATION:-"FILESYSTEM"}
COMPRESSION=${COMPRESSION:-GZ} COMPRESSION=${COMPRESSION:-"GZ"}
COMPRESSION_LEVEL=${COMPRESSION_LEVEL:-"3"} COMPRESSION_LEVEL=${COMPRESSION_LEVEL:-"3"}
DB_DUMP_BEGIN=${DB_DUMP_BEGIN:-+0} DB_DUMP_BEGIN=${DB_DUMP_BEGIN:-+0}
DB_DUMP_FREQ=${DB_DUMP_FREQ:-1440} DB_DUMP_FREQ=${DB_DUMP_FREQ:-1440}
DB_DUMP_TARGET=${DB_DUMP_TARGET:-/backup} 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}
dbuser=${DB_USER} dbuser=${DB_USER}
MD5=${MD5:-TRUE} MD5=${MD5:-TRUE}
PARALLEL_COMPRESSION=${PARALLEL_COMPRESSION:-TRUE} PARALLEL_COMPRESSION=${PARALLEL_COMPRESSION:-"TRUE"}
SIZE_VALUE=${SIZE_VALUE:-"bytes"} SIZE_VALUE=${SIZE_VALUE:-"bytes"}
SPLIT_DB=${SPLIT_DB:-FALSE} SPLIT_DB=${SPLIT_DB:-"FALSE"}
tmpdir=/tmp/backups TEMP_LOCATION=${TEMP_LOCATION:-"/tmp/backups"}
if [ "$BACKUP_TYPE" = "S3" ] || [ "$BACKUP_TYPE" = "s3" ] || [ "$BACKUP_TYPE" = "MINIO" ] || [ "$BACKUP_TYPE" = "minio" ] ; then if [ "$BACKUP_LOCATION" = "S3" ] || [ "$BACKUP_LOCATION" = "s3" ] || [ "$BACKUP_LOCATION" = "MINIO" ] || [ "$BACKUP_LOCATION" = "minio" ] ; then
S3_PROTOCOL=${S3_PROTOCOL:-"https"} S3_PROTOCOL=${S3_PROTOCOL:-"https"}
sanity_var S3_HOST "S3 Host"
sanity_var S3_BUCKET "S3 Bucket" sanity_var S3_BUCKET "S3 Bucket"
sanity_var S3_KEY_ID "S3 Key ID" sanity_var S3_KEY_ID "S3 Key ID"
sanity_var S3_KEY_SECRET "S3 Key Secret" sanity_var S3_KEY_SECRET "S3 Key Secret"
sanity_var S3_URI_STYLE "S3 URI Style (Virtualhost or Path)"
sanity_var S3_PATH "S3 Path" sanity_var S3_PATH "S3 Path"
sanity_var S3_REGION "S3 Region" sanity_var S3_REGION "S3 Region"
file_env 'S3_KEY_ID' file_env 'S3_KEY_ID'
@@ -100,7 +99,7 @@ if [ "$1" = "NOW" ]; then
fi fi
### Set Compression Options ### Set Compression Options
if var_true "$PARALLEL_COMPRESSION" ; then if var_true "${PARALLEL_COMPRESSION}" ; then
bzip="pbzip2 -${COMPRESSION_LEVEL}" bzip="pbzip2 -${COMPRESSION_LEVEL}"
gzip="pigz -${COMPRESSION_LEVEL}" gzip="pigz -${COMPRESSION_LEVEL}"
xzip="pixz -${COMPRESSION_LEVEL}" xzip="pixz -${COMPRESSION_LEVEL}"
@@ -135,7 +134,7 @@ esac
backup_couch() { backup_couch() {
target=couch_${dbname}_${dbhost}_${now}.txt target=couch_${dbname}_${dbhost}_${now}.txt
compression compression
curl -X GET http://${dbhost}:${dbport}/${dbname}/_all_docs?include_docs=true ${dumpoutput} | $dumpoutput > ${tmpdir}/${target} curl -X GET http://${dbhost}:${dbport}/${dbname}/_all_docs?include_docs=true ${dumpoutput} | $dumpoutput > ${TEMP_LOCATION}/${target}
exit_code=$? exit_code=$?
generate_md5 generate_md5
move_backup move_backup
@@ -148,9 +147,9 @@ backup_influx() {
print_notice "Compressing InfluxDB backup with gzip" print_notice "Compressing InfluxDB backup with gzip"
influx_compression="-portable" influx_compression="-portable"
fi fi
for DB in $DB_NAME; do for DB in ${DB_NAME}; do
target=influx_${DB}_${dbhost}_${now} target=influx_${DB}_${dbhost}_${now}
influxd backup ${influx_compression} -database $DB -host ${dbhost}:${dbport} ${tmpdir}/${target} influxd backup ${influx_compression} -database $DB -host ${dbhost}:${dbport} ${TEMP_LOCATION}/${target}
exit_code=$? exit_code=$?
generate_md5 generate_md5
move_backup move_backup
@@ -165,28 +164,28 @@ backup_mongo() {
target=${dbtype}_${dbname}_${dbhost}_${now}.archivegz target=${dbtype}_${dbname}_${dbhost}_${now}.archivegz
mongo_compression="--gzip" mongo_compression="--gzip"
fi fi
mongodump --archive=${tmpdir}/${target} ${mongo_compression} --host ${dbhost} --port ${dbport} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS} mongodump --archive=${TEMP_LOCATION}/${target} ${mongo_compression} --host ${dbhost} --port ${dbport} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS}
exit_code=$? exit_code=$?
cd ${tmpdir} cd ${TEMP_LOCATION}
generate_md5 generate_md5
move_backup move_backup
} }
backup_mssql() { backup_mssql() {
target=mssql_${dbname}_${dbhost}_${now}.bak target=mssql_${dbname}_${dbhost}_${now}.bak
/opt/mssql-tools/bin/sqlcmd -E -C -S ${dbhost}\,${dbport} -U ${dbuser} -P ${dbpass} Q "BACKUP DATABASE \[${dbname}\] TO DISK = N'${tmpdir}/${target}' WITH NOFORMAT, NOINIT, NAME = '${dbname}-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10" /opt/mssql-tools/bin/sqlcmd -E -C -S ${dbhost}\,${dbport} -U ${dbuser} -P ${dbpass} Q "BACKUP DATABASE \[${dbname}\] TO DISK = N'${TEMP_LOCATION}/${target}' WITH NOFORMAT, NOINIT, NAME = '${dbname}-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
} }
backup_mysql() { backup_mysql() {
if var_true "$SPLIT_DB" ; then if var_true "${SPLIT_DB}" ; then
DATABASES=$(mysql -h ${dbhost} -P $dbport -u$dbuser --batch -e "SHOW DATABASES;" | grep -v Database|grep -v schema) DATABASES=$(mysql -h ${dbhost} -P $dbport -u$dbuser --batch -e "SHOW DATABASES;" | grep -v Database | grep -v schema)
for db in $DATABASES; do for db in $DATABASES; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != _* ]] ; then if [[ "$db" != "information_schema" ]] && [[ "$db" != _* ]] ; then
print_notice "Dumping MariaDB database: $db" print_notice "Dumping MariaDB database: $db"
target=mysql_${db}_${dbhost}_${now}.sql target=mysql_${db}_${dbhost}_${now}.sql
compression compression
mysqldump --max-allowed-packet=512M -h $dbhost -P $dbport -u$dbuser ${EXTRA_OPTS} --databases $db | $dumpoutput > ${tmpdir}/${target} mysqldump --max-allowed-packet=${MYSQL_MAX_ALLOWED_PACKET} -h $dbhost -P $dbport -u$dbuser ${EXTRA_OPTS} --databases $db | $dumpoutput > ${TEMP_LOCATION}/${target}
exit_code=$? exit_code=$?
generate_md5 generate_md5
move_backup move_backup
@@ -194,7 +193,7 @@ backup_mysql() {
done done
else else
compression compression
mysqldump --max-allowed-packet=512M -A -h $dbhost -P $dbport -u$dbuser ${EXTRA_OPTS} | $dumpoutput > ${tmpdir}/${target} mysqldump --max-allowed-packet=${MYSQL_MAX_ALLOWED_PACKET} -A -h $dbhost -P $dbport -u$dbuser ${EXTRA_OPTS} | $dumpoutput > ${TEMP_LOCATION}/${target}
exit_code=$? exit_code=$?
generate_md5 generate_md5
move_backup move_backup
@@ -202,7 +201,7 @@ backup_mysql() {
} }
backup_pgsql() { backup_pgsql() {
if var_true $SPLIT_DB ; then if var_true "${SPLIT_DB}" ; then
export PGPASSWORD=${dbpass} export PGPASSWORD=${dbpass}
authdb=${DB_USER} authdb=${DB_USER}
[ -n "${DB_NAME}" ] && authdb=${DB_NAME} [ -n "${DB_NAME}" ] && authdb=${DB_NAME}
@@ -211,7 +210,7 @@ backup_pgsql() {
print_info "Dumping database: $db" print_info "Dumping database: $db"
target=pgsql_${db}_${dbhost}_${now}.sql target=pgsql_${db}_${dbhost}_${now}.sql
compression compression
pg_dump -h ${dbhost} -p ${dbport} -U ${dbuser} $db ${EXTRA_OPTS} | $dumpoutput > ${tmpdir}/${target} pg_dump -h ${dbhost} -p ${dbport} -U ${dbuser} $db ${EXTRA_OPTS} | $dumpoutput > ${TEMP_LOCATION}/${target}
exit_code=$? exit_code=$?
generate_md5 generate_md5
move_backup move_backup
@@ -219,7 +218,7 @@ backup_pgsql() {
else else
export PGPASSWORD=${dbpass} export PGPASSWORD=${dbpass}
compression compression
pg_dump -h ${dbhost} -U ${dbuser} -p ${dbport} ${dbname} ${EXTRA_OPTS} | $dumpoutput > ${tmpdir}/${target} pg_dump -h ${dbhost} -U ${dbuser} -p ${dbport} ${dbname} ${EXTRA_OPTS} | $dumpoutput > ${TEMP_LOCATION}/${target}
exit_code=$? exit_code=$?
generate_md5 generate_md5
move_backup move_backup
@@ -228,7 +227,7 @@ backup_pgsql() {
backup_redis() { backup_redis() {
target=redis_${db}_${dbhost}_${now}.rdb target=redis_${db}_${dbhost}_${now}.rdb
echo bgsave | redis-cli -h ${dbhost} -p ${dbport} ${REDIS_PASS_STR} --rdb ${tmpdir}/${target} ${EXTRA_OPTS} echo bgsave | redis-cli -h ${dbhost} -p ${dbport} ${REDIS_PASS_STR} --rdb ${TEMP_LOCATION}/${target} ${EXTRA_OPTS}
print_info "Dumping Redis - Flushing Redis Cache First" print_info "Dumping Redis - Flushing Redis Cache First"
sleep 10 sleep 10
try=5 try=5
@@ -245,7 +244,7 @@ backup_redis() {
done done
target_original=${target} target_original=${target}
compression compression
$dumpoutput "${tmpdir}/${target_original}" $dumpoutput "${TEMP_LOCATION}/${target_original}"
generate_md5 generate_md5
move_backup move_backup
} }
@@ -257,10 +256,10 @@ backup_sqlite3() {
compression compression
print_info "Dumping sqlite3 database: ${dbhost}" print_info "Dumping sqlite3 database: ${dbhost}"
sqlite3 "${dbhost}" ".backup '${tmpdir}/backup.sqlite3'" sqlite3 "${dbhost}" ".backup '${TEMP_LOCATION}/backup.sqlite3'"
exit_code=$? exit_code=$?
cat "${tmpdir}/backup.sqlite3" | $dumpoutput > "${tmpdir}/${target}" cat "${TEMP_LOCATION}/backup.sqlite3" | $dumpoutput > "${TEMP_LOCATION}/${target}"
generate_md5 generate_md5
move_backup move_backup
@@ -296,17 +295,10 @@ check_availability() {
"mysql" ) "mysql" )
COUNTER=0 COUNTER=0
export MYSQL_PWD=${dbpass} export MYSQL_PWD=${dbpass}
while true; do while ! (mysqladmin -u"${dbuser}" -P"${dbport}" -h"${dbhost}" status > /dev/null 2>&1) ; do
mysqlcmd='mysql -u'${dbuser}' -P '${dbport}' -h '${dbhost}
out="$($mysqlcmd -e "SELECT COUNT(*) FROM information_schema.FILES;" 2>&1)"
echo "$out" | grep -E "COUNT|Enter" 2>&1 > /dev/null
if [ $? -eq 0 ]; then
:
break
fi
print_warn "MySQL/MariaDB Server '${dbhost}' is not accessible, retrying.. ($COUNTER seconds so far)"
sleep 5 sleep 5
(( COUNTER+=5 )) (( COUNTER+=5 ))
print_warn "MySQL/MariaDB Server '${dbhost}' is not accessible, retrying.. (${COUNTER} seconds so far)"
done done
;; ;;
"mssql" ) "mssql" )
@@ -384,7 +376,7 @@ compression() {
generate_md5() { generate_md5() {
if var_true "$MD5" ; then if var_true "$MD5" ; then
print_notice "Generating MD5 for ${target}" print_notice "Generating MD5 for ${target}"
cd $tmpdir cd ${TEMP_LOCATION}
md5sum "${target}" > "${target}".md5 md5sum "${target}" > "${target}".md5
MD5VALUE=$(md5sum "${target}" | awk '{ print $1}') MD5VALUE=$(md5sum "${target}" | awk '{ print $1}')
fi fi
@@ -404,18 +396,18 @@ move_backup() {
;; ;;
esac esac
if [ "$SIZE_VALUE" = "1" ] ; then if [ "$SIZE_VALUE" = "1" ] ; then
FILESIZE=$(stat -c%s "${tmpdir}/${target}") FILESIZE=$(stat -c%s "${TEMP_LOCATION}/${target}")
print_notice "Backup of ${target} created with the size of ${FILESIZE} bytes" print_notice "Backup of ${target} created with the size of ${FILESIZE} bytes"
else else
FILESIZE=$(du -h "${tmpdir}/${target}" | awk '{ print $1}') FILESIZE=$(du -h "${TEMP_LOCATION}/${target}" | awk '{ print $1}')
print_notice "Backup of ${target} created with the size of ${FILESIZE}" print_notice "Backup of ${target} created with the size of ${FILESIZE}"
fi fi
case "${BACKUP_LOCATION}" in case "${BACKUP_LOCATION}" in
"FILE" | "file" | "filesystem" | "FILESYSTEM" ) "FILE" | "file" | "filesystem" | "FILESYSTEM" )
mkdir -p "${DB_DUMP_TARGET}" mkdir -p "${DB_DUMP_TARGET}"
mv ${tmpdir}/*.md5 "${DB_DUMP_TARGET}"/ mv ${TEMP_LOCATION}/*.md5 "${DB_DUMP_TARGET}"/
mv ${tmpdir}/"${target}" "${DB_DUMP_TARGET}"/"${target}" mv ${TEMP_LOCATION}/"${target}" "${DB_DUMP_TARGET}"/"${target}"
;; ;;
"S3" | "s3" | "MINIO" | "minio" ) "S3" | "s3" | "MINIO" | "minio" )
export AWS_ACCESS_KEY_ID=${S3_KEY_ID} export AWS_ACCESS_KEY_ID=${S3_KEY_ID}
@@ -424,10 +416,10 @@ move_backup() {
[[ ( -n "${S3_HOST}" ) ]] && PARAM_AWS_ENDPOINT_URL=" --endpoint-url ${S3_PROTOCOL}://${S3_HOST}" [[ ( -n "${S3_HOST}" ) ]] && PARAM_AWS_ENDPOINT_URL=" --endpoint-url ${S3_PROTOCOL}://${S3_HOST}"
aws ${PARAM_AWS_ENDPOINT_URL} s3 cp ${tmpdir}/${target} s3://${S3_BUCKET}/${S3_PATH}/${target} aws ${PARAM_AWS_ENDPOINT_URL} s3 cp ${TEMP_LOCATION}/${target} s3://${S3_BUCKET}/${S3_PATH}/${target}
rm -rf ${tmpdir}/*.md5 rm -rf ${TEMP_LOCATION}/*.md5
rm -rf ${tmpdir}/"${target}" rm -rf ${TEMP_LOCATION}/"${target}"
;; ;;
esac esac
} }
@@ -460,7 +452,7 @@ print_debug "Backup routines Initialized on $(date)"
### Commence Backup ### Commence Backup
while true; do while true; do
# make sure the directory exists # make sure the directory exists
mkdir -p $tmpdir mkdir -p $TEMP_LOCATION
### Define Target name ### Define Target name
now=$(date +"%Y%m%d-%H%M%S") now=$(date +"%Y%m%d-%H%M%S")
@@ -535,7 +527,7 @@ print_debug "Backup routines Initialized on $(date)"
### Go back to Sleep until next Backup time ### Go back to Sleep until next Backup time
if var_true $MANUAL ; then if var_true $MANUAL ; then
exit 1; exit 0;
else else
sleep $(($DB_DUMP_FREQ*60)) sleep $(($DB_DUMP_FREQ*60))
fi fi