mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-21 13:23:12 +01:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c81d8e2713 | ||
|
|
b808b35624 | ||
|
|
e060aeb0e5 | ||
|
|
03c16cc582 | ||
|
|
e45d916b00 | ||
|
|
eb0ee61662 | ||
|
|
8e737eb579 | ||
|
|
5d2043a603 | ||
|
|
89fe251321 | ||
|
|
e9052f1cd6 | ||
|
|
a73528c5b2 | ||
|
|
7d1e112dfc | ||
|
|
e0bb4c313b | ||
|
|
cb5333a59c | ||
|
|
7b59632378 | ||
|
|
353b1af7b4 | ||
|
|
a27b46a43a | ||
|
|
e5b9ee2cc0 | ||
|
|
6ddb749bc6 | ||
|
|
fb299c41dd | ||
|
|
d7d4f1cc19 | ||
|
|
c8c9a80533 | ||
|
|
018234b9bc | ||
|
|
912e60edd8 | ||
|
|
46fddb533c | ||
|
|
e8a1859d1a | ||
|
|
30fe2f181c | ||
|
|
f57ce461e9 |
42
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
42
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: If something isn't working right..
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### Summary
|
||||
|
||||
<!-- Summarize the bug encountered -->
|
||||
|
||||
|
||||
### Steps to reproduce
|
||||
|
||||
<!-- Describe how one can reproduce the issue - this is very important. Please use an ordered list. -->
|
||||
|
||||
|
||||
### What is the expected *correct* behavior?
|
||||
|
||||
<!-- Describe what should be seen instead. -->
|
||||
|
||||
|
||||
### Relevant logs and/or screenshots
|
||||
|
||||
<!-- Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's tough to read otherwise. -->
|
||||
|
||||
### Environment
|
||||
<!--Your Configuration (please complete the following information): -->
|
||||
|
||||
- Image version / tag:
|
||||
- Host OS:
|
||||
|
||||
<details>
|
||||
<summary>Any logs | docker-compose.yml</summary>
|
||||
</details>
|
||||
|
||||
<!-- Include anything additional -->
|
||||
|
||||
### Possible fixes
|
||||
<!-- If you can, provide details to the root cause that might be responsible for the problem. -->
|
||||
23
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
23
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea or feature
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
name: Feature Request
|
||||
about: Suggest an idea for this project
|
||||
|
||||
---
|
||||
|
||||
**Description of the feature**
|
||||
<!-- A clear description of the feature you'd like implemented -->
|
||||
|
||||
**Benftits of feature**
|
||||
<!-- Explain the measurable benefits this feature would achieve. -->
|
||||
|
||||
**Additional context**
|
||||
<!--Add any other context or screenshots about the feature request here. -->
|
||||
5
.github/workflows/main.yml
vendored
5
.github/workflows/main.yml
vendored
@@ -1,7 +1,7 @@
|
||||
### Application Level Image CI
|
||||
### Dave Conroy <dave at tiredofit dot ca>
|
||||
|
||||
name: 'Build Images'
|
||||
name: 'build'
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -70,9 +70,6 @@ jobs:
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
run: |
|
||||
docker buildx inspect --bootstrap
|
||||
|
||||
|
||||
- name: Login to DockerHub
|
||||
if: github.event_name != 'pull_request'
|
||||
|
||||
40
CHANGELOG.md
40
CHANGELOG.md
@@ -1,3 +1,43 @@
|
||||
## 2.8.1 2021-09-01 <dave at tiredofit dot ca>
|
||||
|
||||
### Changed
|
||||
- Modernize image with updated environment varialbes from upstream
|
||||
|
||||
|
||||
## 2.8.0 2021-08-27 <dave at tiredofit dot ca>
|
||||
|
||||
### Added
|
||||
- Alpine 3.14 Base
|
||||
|
||||
### Changed
|
||||
- Fix for syntax error in 2.7.0 Release (Credit the1ts@github)
|
||||
- Cleanup image and leftover cache with AWS CLI installation
|
||||
|
||||
|
||||
## 2.7.0 2021-06-17 <dave at tiredofit dot ca>
|
||||
|
||||
### Added
|
||||
- MongoDB Authentication Database support (DB_AUTH)
|
||||
|
||||
|
||||
## 2.6.1 2021-06-08 <jwillmer@github>
|
||||
|
||||
### Changed
|
||||
- Fix for Issue #14 - SPLIT_DB=TRUE was not working for Postgres DB server
|
||||
|
||||
|
||||
## 2.6.0 2021-02-19 <tpansino@github>
|
||||
|
||||
### Added
|
||||
- SQLite support
|
||||
|
||||
|
||||
## 2.5.1 2021-02-14 <dave at tiredofit dot ca>
|
||||
|
||||
### Changed
|
||||
- Fix xz backups with `PARALLEL_COMPRESION=TRUE`
|
||||
|
||||
|
||||
## 2.5.0 2021-01-25 <dave at tiredofit dot ca>
|
||||
|
||||
### Added
|
||||
|
||||
24
Dockerfile
24
Dockerfile
@@ -1,11 +1,11 @@
|
||||
FROM tiredofit/alpine:3.13
|
||||
FROM tiredofit/alpine:3.14
|
||||
|
||||
### Set Environment Variables
|
||||
ENV MSSQL_VERSION=17.5.2.1-1 \
|
||||
ENABLE_CRON=FALSE \
|
||||
ENABLE_SMTP=FALSE \
|
||||
ENABLE_ZABBIX=TRUE \
|
||||
ZABBIX_HOSTNAME=db-backup
|
||||
CONTAINER_ENABLE_SCHEDULING=FALSE \
|
||||
CONTAINER_ENABLE_MESSAGING=FALSE \
|
||||
CONTAINER_ENABLE_MONITORING=TRUE \
|
||||
CONTAINER_NAME=db-backup
|
||||
|
||||
### Dependencies
|
||||
RUN set -ex && \
|
||||
@@ -16,19 +16,23 @@ RUN set -ex && \
|
||||
bzip2-dev \
|
||||
git \
|
||||
libarchive-dev \
|
||||
py3-pip \
|
||||
xz-dev \
|
||||
&& \
|
||||
\
|
||||
apk add --no-cache -t .db-backup-run-deps \
|
||||
bzip2 \
|
||||
influxdb \
|
||||
libarchive \
|
||||
mariadb-client \
|
||||
mongodb-tools \
|
||||
libressl \
|
||||
pigz \
|
||||
postgresql \
|
||||
postgresql-client \
|
||||
python3 \
|
||||
redis \
|
||||
sqlite \
|
||||
xz \
|
||||
zstd \
|
||||
&& \
|
||||
@@ -53,13 +57,15 @@ RUN set -ex && \
|
||||
--sysconfdir=/etc \
|
||||
--localstatedir=/var \
|
||||
&& \
|
||||
make && \
|
||||
make install && \
|
||||
\
|
||||
make && \
|
||||
make install && \
|
||||
pip3 install --upgrade pip && \
|
||||
pip3 install awscli && \
|
||||
\
|
||||
### Cleanup
|
||||
apk del .db-backup-build-deps && \
|
||||
rm -rf /usr/src/* && \
|
||||
rm -rf /tmp/* /var/cache/apk/*
|
||||
rm -rf /root/.cache /tmp/* /var/cache/apk/*
|
||||
|
||||
### S6 Setup
|
||||
ADD install /
|
||||
|
||||
168
README.md
168
README.md
@@ -1,13 +1,16 @@
|
||||
# hub.docker.com/r/tiredofit/db-backup
|
||||
# github.com/tiredofit/docker-db-backup
|
||||
|
||||
[](https://hub.docker.com/r/tiredofit/db-backup)
|
||||
[](https://hub.docker.com/r/tiredofit/db-backup)
|
||||
[](https://hub.docker.com/r/tiredofit/db-backup)
|
||||
[](https://microbadger.com/images/tiredofit/db-backup)
|
||||
[](https://github.com/tiredofit/docker-db-backup/releases/latest)
|
||||
[](https://github.com/tiredofit/docker-db-backup/actions?query=workflow%3Abuild)
|
||||
[](https://hub.docker.com/r/tiredofit/db-backup/)
|
||||
[](https://hub.docker.com/r/tiredofit/db-backup/)
|
||||
[](https://github.com/sponsors/tiredofit)
|
||||
[](https://www.paypal.me/tiredofit)
|
||||
|
||||
## Introduction
|
||||
* * *
|
||||
## About
|
||||
|
||||
This will build a container for backing up multiple type of DB Servers
|
||||
This will build a container for backing up multiple types of DB Servers
|
||||
|
||||
Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
|
||||
|
||||
@@ -22,53 +25,61 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
|
||||
* select when to start the first dump, whether time of day or relative to container start time
|
||||
* Execute script after backup for monitoring/alerting purposes
|
||||
|
||||
* This Container uses a [customized Alpine Linux base](https://hub.docker.com/r/tiredofit/alpine) which includes [s6 overlay](https://github.com/just-containers/s6-overlay) enabled for PID 1 Init capabilities, [zabbix-agent](https://zabbix.org) for individual container monitoring, Cron also installed along with other tools (bash,curl, less, logrotate, nano, vim) for easier management. It also supports sending to external SMTP servers.
|
||||
|
||||
[Changelog](CHANGELOG.md)
|
||||
|
||||
## Authors
|
||||
## Maintainer
|
||||
|
||||
- [Dave Conroy](https://github.com/tiredofit)
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [hub.docker.com/r/tiredofit/db-backup](#hubdockercomrtiredofitdb-backup)
|
||||
- [Introduction](#introduction)
|
||||
- [Authors](#authors)
|
||||
- [Table of Contents](#table-of-contents)
|
||||
- [Prerequisites](#prerequisites)
|
||||
- [Installation](#installation)
|
||||
- [Quick Start](#quick-start)
|
||||
- [Configuration](#configuration)
|
||||
- [Data-Volumes](#data-volumes)
|
||||
- [Environment Variables](#environment-variables)
|
||||
- [Maintenance](#maintenance)
|
||||
- [Shell Access](#shell-access)
|
||||
- [Custom Scripts](#custom-scripts)
|
||||
- [Example Post Script](#example-post-script)
|
||||
- [$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)
|
||||
- [About](#about)
|
||||
- [Maintainer](#maintainer)
|
||||
- [Table of Contents](#table-of-contents)
|
||||
- [Prerequisites and Assumptions](#prerequisites-and-assumptions)
|
||||
- [Installation](#installation)
|
||||
- [Build from Source](#build-from-source)
|
||||
- [Prebuilt Images](#prebuilt-images)
|
||||
- [Configuration](#configuration)
|
||||
- [Quick Start](#quick-start)
|
||||
- [Persistent Storage](#persistent-storage)
|
||||
- [Environment Variables](#environment-variables)
|
||||
- [Base Images used](#base-images-used)
|
||||
- [Backing Up to S3 Compatible Services](#backing-up-to-s3-compatible-services)
|
||||
- [Maintenance](#maintenance)
|
||||
- [Shell Access](#shell-access)
|
||||
- [Manual Backups](#manual-backups)
|
||||
- [Custom Scripts](#custom-scripts)
|
||||
- [Support](#support)
|
||||
- [Usage](#usage)
|
||||
- [Bugfixes](#bugfixes)
|
||||
- [Feature Requests](#feature-requests)
|
||||
- [Updates](#updates)
|
||||
- [License](#license)
|
||||
|
||||
## Prerequisites
|
||||
## Prerequisites and Assumptions
|
||||
|
||||
You must have a working DB server or container available for this to work properly, it does not provide server functionality!
|
||||
|
||||
## Installation
|
||||
|
||||
Automated builds of the image are available on [Docker Hub](https://hub.docker.com/r/tiredofit/db-backup) and is the recommended
|
||||
method of installation.
|
||||
### Build from Source
|
||||
Clone this repository and build the image with `docker build -t (imagename) .`
|
||||
|
||||
### Prebuilt Images
|
||||
Builds of the image are available on [Docker Hub](https://hub.docker.com/r/tiredofit/db-backup) and is the recommended method of installation.
|
||||
|
||||
```bash
|
||||
docker pull tiredofit/db-backup:latest
|
||||
docker pull tiredofit/db-backup:(imagetag)
|
||||
```
|
||||
|
||||
The following image tags are available along with their tagged release based on what's written in the [Changelog](CHANGELOG.md):
|
||||
|
||||
| Container OS | Tag |
|
||||
| ------------ | --------- |
|
||||
| Alpine | `:latest` |
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
### Quick Start
|
||||
|
||||
* The quickest way to get started is using [docker-compose](https://docs.docker.com/compose/). See the examples folder for a working [docker-compose.yml](examples/docker-compose.yml) that can be modified for development or production use.
|
||||
@@ -77,10 +88,7 @@ docker pull tiredofit/db-backup:latest
|
||||
* Map [persistent storage](#data-volumes) for access to configuration and data files for backup.
|
||||
|
||||
> **NOTE**: If you are using this with a docker-compose file along with a seperate SQL container, take care not to set the variables to backup immediately, more so have it delay execution for a minute, otherwise you will get a failed first backup.
|
||||
|
||||
## Configuration
|
||||
|
||||
### Data-Volumes
|
||||
### Persistent Storage
|
||||
|
||||
The following directories are used for configuration and can be mapped for persistent storage.
|
||||
|
||||
@@ -88,18 +96,27 @@ The following directories are used for configuration and can be mapped for persi
|
||||
| ------------------------ | ---------------------------------------------------------------------------------- |
|
||||
| `/backup` | Backups |
|
||||
| `/assets/custom-scripts` | *Optional* Put custom scripts in this directory to execute after backup operations |
|
||||
|
||||
### Environment Variables
|
||||
|
||||
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.
|
||||
#### Base Images used
|
||||
|
||||
This image relies on an [Alpine Linux](https://hub.docker.com/r/tiredofit/alpine) base image that relies on an [init system](https://github.com/just-containers/s6-overlay) for added capabilities. Outgoing SMTP capabilities are handlded via `msmtp`. Individual container performance monitoring is performed by [zabbix-agent](https://zabbix.org). Additional tools include: `bash`,`curl`,`less`,`logrotate`, `nano`,`vim`.
|
||||
|
||||
Be sure to view the following repositories to understand all the customizable options:
|
||||
|
||||
| Image | Description |
|
||||
| ------------------------------------------------------ | -------------------------------------- |
|
||||
| [OS Base](https://github.com/tiredofit/docker-alpine/) | Customized Image based on Alpine Linux |
|
||||
|
||||
|
||||
| Parameter | Description |
|
||||
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `BACKUP_LOCATION` | Backup to `FILESYSTEM` or `S3` compatible services like S3, Minio, Wasabi - Default `FILESYSTEM` |
|
||||
| `COMPRESSION` | Use either Gzip `GZ`, Bzip2 `BZ`, XZip `XZ`, ZSTD `ZSTD` or none `NONE` - Default `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` |
|
||||
| `DB_TYPE` | Type of DB Server to backup `couch` `influx` `mysql` `pgsql` `mongo` `redis` |
|
||||
| `DB_HOST` | Server Hostname e.g. `mariadb` |
|
||||
| `DB_AUTH` | (Mongo Only - Optional) Authentication Database |
|
||||
| `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_NAME` | Schema Name e.g. `database` |
|
||||
| `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 |
|
||||
@@ -118,33 +135,36 @@ Along with the Environment Variables from the [Base image](https://hub.docker.co
|
||||
|
||||
When using compression with MongoDB, only `GZ` compression is possible.
|
||||
|
||||
**Backing Up to S3 Compatible Services**
|
||||
#### Backing Up to S3 Compatible Services
|
||||
|
||||
If `BACKUP_LOCATION` = `S3` then the following options are used.
|
||||
|
||||
| Parameter | Description |
|
||||
| --------------- | --------------------------------------------------------------------------------------- |
|
||||
| `S3_BUCKET` | S3 Bucket name e.g. 'mybucket' |
|
||||
| `S3_HOSTNAME` | Hostname of S3 Server e.g "s3.amazonaws.com" - You can also include a port if necessary |
|
||||
| `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_SECRET` | S3 Key Secret |
|
||||
| `S3_PATH` | S3 Pathname to save to e.g. '`backup`' |
|
||||
| `S3_PROTOCOL` | Use either `http` or `https` to access service - Default `https` |
|
||||
| `S3_URI_STYLE` | Choose either `VIRTUALHOST` or `PATH` style - Default `VIRTUALHOST` |
|
||||
|
||||
|
||||
## Maintenance
|
||||
|
||||
Manual Backups can be performed by entering the container and typing `backup-now`
|
||||
|
||||
### Shell Access
|
||||
|
||||
For debugging and maintenance purposes you may want access the containers shell.
|
||||
|
||||
```bash
|
||||
docker exec -it (whatever your container name is e.g.) db-backup bash
|
||||
```
|
||||
``bash
|
||||
docker exec -it (whatever your container name is) bash
|
||||
``
|
||||
### Manual Backups
|
||||
Manual Backups can be performed by entering the container and typing `backup-now`
|
||||
|
||||
#### Custom Scripts
|
||||
|
||||
### Custom Scripts
|
||||
|
||||
If you want to execute a custom script at the end of backup, you can drop bash scripts with the extension of `.sh` in this directory. See the following example to utilize:
|
||||
|
||||
@@ -152,16 +172,16 @@ If you want to execute a custom script at the end of backup, you can drop bash s
|
||||
$ cat post-script.sh
|
||||
##!/bin/bash
|
||||
|
||||
## Example Post Script
|
||||
## $1=EXIT_CODE (After running backup routine)
|
||||
## $2=DB_TYPE (Type of Backup)
|
||||
## $3=DB_HOST (Backup Host)
|
||||
## #4=DB_NAME (Name of Database backed up
|
||||
## $5=DATE (Date of Backup)
|
||||
## $6=TIME (Time of Backup)
|
||||
## $7=BACKUP_FILENAME (Filename of Backup)
|
||||
## $8=FILESIZE (Filesize of backup)
|
||||
## $9=MD5_RESULT (MD5Sum if enabled)
|
||||
# #### Example Post Script
|
||||
# #### $1=EXIT_CODE (After running backup routine)
|
||||
# #### $2=DB_TYPE (Type of Backup)
|
||||
# #### $3=DB_HOST (Backup Host)
|
||||
# #### #4=DB_NAME (Name of Database backed up
|
||||
# #### $5=DATE (Date of Backup)
|
||||
# #### $6=TIME (Time of Backup)
|
||||
# #### $7=BACKUP_FILENAME (Filename of Backup)
|
||||
# #### $8=FILESIZE (Filesize of backup)
|
||||
# #### $9=MD5_RESULT (MD5Sum if enabled)
|
||||
|
||||
echo "${1} ${2} Backup Completed on ${3} for ${4} on ${5} ${6}. Filename: ${7} Size: ${8} bytes MD5: ${9}"
|
||||
````
|
||||
@@ -171,3 +191,23 @@ Outputs the following on the console:
|
||||
`0 mysql Backup Completed on example-db for example on 2020-04-22 05:19:10. Filename: mysql_example_example-db_20200422-051910.sql.bz2 Size: 7795 bytes MD5: 952fbaafa30437494fdf3989a662cd40`
|
||||
|
||||
If you wish to change the size value from bytes to megabytes set environment variable `SIZE_VALUE=megabytes`
|
||||
|
||||
## Support
|
||||
|
||||
These images were built to serve a specific need in a production environment and gradually have had more functionality added based on requests from the community.
|
||||
### Usage
|
||||
- The [Discussions board](../../discussions) is a great place for working with the community on tips and tricks of using this image.
|
||||
- Consider [sponsoring me](https://github.com/sponsors/tiredofit) personalized support.
|
||||
### Bugfixes
|
||||
- Please, submit a [Bug Report](issues/new) if something isn't working as expected. I'll do my best to issue a fix in short order.
|
||||
|
||||
### Feature Requests
|
||||
- Feel free to submit a feature request, however there is no guarantee that it will be added, or at what timeline.
|
||||
- Consider [sponsoring me](https://github.com/sponsors/tiredofit) regarding development of features.
|
||||
|
||||
### Updates
|
||||
- Best effort to track upstream changes, More priority if I am actively using the image in a production environment.
|
||||
- Consider [sponsoring me](https://github.com/sponsors/tiredofit) for up to date releases.
|
||||
|
||||
## License
|
||||
MIT. See [LICENSE](LICENSE) for more details.
|
||||
|
||||
0
examples/docker-compose.yml
Normal file → Executable file
0
examples/docker-compose.yml
Normal file → Executable file
0
install/etc/cont-finish.d/10-db-backup
Normal file → Executable file
0
install/etc/cont-finish.d/10-db-backup
Normal file → Executable file
@@ -60,6 +60,9 @@ case "$dbtype" in
|
||||
dbport=${DB_PORT:-6379}
|
||||
[[ ( -n "${DB_PASS}" || ( -n "${DB_PASS_FILE}" ) ) ]] && file_env 'DB_PASS'
|
||||
;;
|
||||
"sqlite" | "sqlite3" | "SQLITE" | "SQLITE3" )
|
||||
dbtype=sqlite3
|
||||
;;
|
||||
esac
|
||||
|
||||
### Set Defaults
|
||||
@@ -115,6 +118,7 @@ case "$dbtype" in
|
||||
[[ ( -n "${DB_USER}" ) ]] && MONGO_USER_STR=" --username ${dbuser}"
|
||||
[[ ( -n "${DB_PASS}" ) ]] && MONGO_PASS_STR=" --password ${dbpass}"
|
||||
[[ ( -n "${DB_NAME}" ) ]] && MONGO_DB_STR=" --db ${dbname}"
|
||||
[[ ( -n "${DB_AUTH}" ) ]] && MONGO_AUTH_STR=" --authenticationDatabase ${DB_AUTH}"
|
||||
;;
|
||||
"mysql" )
|
||||
[[ ( -n "${DB_PASS}" ) ]] && export MYSQL_PWD=${dbpass}
|
||||
@@ -161,7 +165,7 @@ backup_mongo() {
|
||||
target=${dbtype}_${dbname}_${dbhost}_${now}.archivegz
|
||||
mongo_compression="--gzip"
|
||||
fi
|
||||
mongodump --archive=${tmpdir}/${target} ${mongo_compression} --host ${dbhost} --port ${dbport} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_DB_STR} ${EXTRA_OPTS}
|
||||
mongodump --archive=${tmpdir}/${target} ${mongo_compression} --host ${dbhost} --port ${dbport} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS}
|
||||
exit_code=$?
|
||||
cd ${tmpdir}
|
||||
generate_md5
|
||||
@@ -200,7 +204,9 @@ backup_mysql() {
|
||||
backup_pgsql() {
|
||||
if var_true $SPLIT_DB ; then
|
||||
export PGPASSWORD=${dbpass}
|
||||
DATABASES=$(psql -h $dbhost -U $dbuser -p ${dbport} -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' )
|
||||
authdb=${DB_USER}
|
||||
[ -n "${DB_NAME}" ] && authdb=${DB_NAME}
|
||||
DATABASES=$(psql -h $dbhost -U $dbuser -p ${dbport} -d ${authdb} -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' )
|
||||
for db in $DATABASES; do
|
||||
print_info "Dumping database: $db"
|
||||
target=pgsql_${db}_${dbhost}_${now}.sql
|
||||
@@ -210,13 +216,13 @@ backup_pgsql() {
|
||||
generate_md5
|
||||
move_backup
|
||||
done
|
||||
else
|
||||
export PGPASSWORD=${dbpass}
|
||||
compression
|
||||
pg_dump -h ${dbhost} -U ${dbuser} -p ${dbport} ${dbname} ${EXTRA_OPTS} | $dumpoutput > ${tmpdir}/${target}
|
||||
exit_code=$?
|
||||
generate_md5
|
||||
move_backup
|
||||
else
|
||||
export PGPASSWORD=${dbpass}
|
||||
compression
|
||||
pg_dump -h ${dbhost} -U ${dbuser} -p ${dbport} ${dbname} ${EXTRA_OPTS} | $dumpoutput > ${tmpdir}/${target}
|
||||
exit_code=$?
|
||||
generate_md5
|
||||
move_backup
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -241,6 +247,22 @@ backup_redis() {
|
||||
move_backup
|
||||
}
|
||||
|
||||
backup_sqlite3() {
|
||||
db=$(basename "$dbhost")
|
||||
db="${db%.*}"
|
||||
target=sqlite3_${db}_${now}.sqlite3
|
||||
compression
|
||||
|
||||
print_info "Dumping sqlite3 database: ${dbhost}"
|
||||
sqlite3 "${dbhost}" ".backup '${tmpdir}/backup.sqlite3'"
|
||||
exit_code=$?
|
||||
|
||||
cat "${tmpdir}/backup.sqlite3" | $dumpoutput > "${tmpdir}/${target}"
|
||||
|
||||
generate_md5
|
||||
move_backup
|
||||
}
|
||||
|
||||
check_availability() {
|
||||
### Set the Database Type
|
||||
case "$dbtype" in
|
||||
@@ -309,6 +331,21 @@ check_availability() {
|
||||
print_warn "Redis Host '${dbhost}' is not accessible, retrying.. ($COUNTER seconds so far)"
|
||||
done
|
||||
;;
|
||||
"sqlite3" )
|
||||
if [[ ! -e "${dbhost}" ]]; then
|
||||
print_error "File '${dbhost}' does not exist."
|
||||
exit_code=2
|
||||
exit $exit_code
|
||||
elif [[ ! -f "${dbhost}" ]]; then
|
||||
print_error "File '${dbhost}' is not a file."
|
||||
exit_code=2
|
||||
exit $exit_code
|
||||
elif [[ ! -r "${dbhost}" ]]; then
|
||||
print_error "File '${dbhost}' is not readable."
|
||||
exit_code=2
|
||||
exit $exit_code
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -377,34 +414,10 @@ move_backup() {
|
||||
mv ${tmpdir}/"${target}" "${DB_DUMP_TARGET}"/"${target}"
|
||||
;;
|
||||
"S3" | "s3" | "MINIO" | "minio" )
|
||||
s3_content_type="application/octet-stream"
|
||||
if [ "$S3_URI_STYLE" = "VIRTUALHOST" ] || [ "$S3_URI_STYLE" = "VHOST" ] || [ "$S3_URI_STYLE" = "virtualhost" ] || [ "$S3_URI_STYLE" = "vhost" ] ; then
|
||||
s3_url="${S3_BUCKET}.${S3_HOST}"
|
||||
else
|
||||
s3_url="${S3_HOST}/${S3_BUCKET}"
|
||||
fi
|
||||
|
||||
if var_true "$MD5" ; then
|
||||
s3_date="$(LC_ALL=C date -u +"%a, %d %b %Y %X %z")"
|
||||
s3_md5="$(libressl md5 -binary < "${tmpdir}/${target}.md5" | base64)"
|
||||
sig="$(printf "PUT\n$s3_md5\n${s3_content_type}\n$s3_date\n/$S3_BUCKET/$S3_PATH/${target}.md5" | libressl sha1 -binary -hmac "${S3_KEY_SECRET}" | base64)"
|
||||
print_debug "Uploading ${target}.md5 to S3"
|
||||
curl -T "${tmpdir}/${target}.md5" "${S3_PROTOCOL}"://"${s3_url}"/"${S3_PATH}"/"${target}".md5 \
|
||||
-H "Date: $date" \
|
||||
-H "Authorization: AWS ${S3_KEY_ID}:$sig" \
|
||||
-H "Content-Type: ${s3_content_type}" \
|
||||
-H "Content-MD5: ${s3_md5}"
|
||||
fi
|
||||
|
||||
s3_date="$(LC_ALL=C date -u +"%a, %d %b %Y %X %z")"
|
||||
s3_md5="$(libressl md5 -binary < "${tmpdir}/${target}" | base64)"
|
||||
sig="$(printf "PUT\n$s3_md5\n${s3_content_type}\n$s3_date\n/$S3_BUCKET/$S3_PATH/${target}" | libressl sha1 -binary -hmac "${S3_KEY_SECRET}" | base64)"
|
||||
print_debug "Uploading ${target} to S3"
|
||||
curl -T ${tmpdir}/"${target}" "${S3_PROTOCOL}"://"${s3_url}"/"${S3_PATH}"/"${target}" \
|
||||
-H "Date: $s3_date" \
|
||||
-H "Authorization: AWS ${S3_KEY_ID}:$sig" \
|
||||
-H "Content-Type: ${s3_content_type}" \
|
||||
-H "Content-MD5: ${s3_md5}"
|
||||
export AWS_ACCESS_KEY_ID=${S3_KEY_ID}
|
||||
export AWS_SECRET_ACCESS_KEY=${S3_KEY_SECRET}
|
||||
export AWS_DEFAULT_REGION=ap-northeast-2
|
||||
aws s3 cp ${tmpdir}/${target} s3://${S3_BUCKET}/${S3_PATH}/${target}
|
||||
|
||||
rm -rf ${tmpdir}/*.md5
|
||||
rm -rf ${tmpdir}/"${target}"
|
||||
@@ -477,10 +490,14 @@ print_debug "Backup routines Initialized on $(date)"
|
||||
check_availability
|
||||
backup_redis
|
||||
;;
|
||||
"sqlite3" )
|
||||
check_availability
|
||||
backup_sqlite3
|
||||
;;
|
||||
esac
|
||||
|
||||
### Zabbix
|
||||
if var_true "$ENABLE_ZABBIX" ; then
|
||||
if var_true "$CONTAINER_ENABLE_MONITORING}" ; then
|
||||
print_notice "Sending Backup Statistics to Zabbix"
|
||||
silent zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -k dbbackup.size -o "$(stat -c%s "${DB_DUMP_TARGET}"/"${target}")"
|
||||
silent zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -k dbbackup.datetime -o "$(date -r "${DB_DUMP_TARGET}"/"${target}" +'%s')"
|
||||
|
||||
Reference in New Issue
Block a user