mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-27 07:31:39 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9159783691 | ||
|
|
7e5e9d308d |
1
.github/workflows/main.yml
vendored
1
.github/workflows/main.yml
vendored
@@ -19,6 +19,7 @@ jobs:
|
|||||||
id: prep
|
id: prep
|
||||||
run: |
|
run: |
|
||||||
DOCKER_IMAGE=${GITHUB_REPOSITORY/docker-/}
|
DOCKER_IMAGE=${GITHUB_REPOSITORY/docker-/}
|
||||||
|
set -x
|
||||||
if [[ $GITHUB_REF == refs/heads/* ]]; then
|
if [[ $GITHUB_REF == refs/heads/* ]]; then
|
||||||
if [[ $GITHUB_REF == refs/heads/*/* ]] ; then
|
if [[ $GITHUB_REF == refs/heads/*/* ]] ; then
|
||||||
BRANCH="${DOCKER_IMAGE}:$(echo $GITHUB_REF | sed "s|refs/heads/||g" | sed "s|/|-|g")"
|
BRANCH="${DOCKER_IMAGE}:$(echo $GITHUB_REF | sed "s|refs/heads/||g" | sed "s|/|-|g")"
|
||||||
|
|||||||
1
.github/workflows/manual.yml
vendored
1
.github/workflows/manual.yml
vendored
@@ -19,6 +19,7 @@ jobs:
|
|||||||
id: prep
|
id: prep
|
||||||
run: |
|
run: |
|
||||||
DOCKER_IMAGE=${GITHUB_REPOSITORY/docker-/}
|
DOCKER_IMAGE=${GITHUB_REPOSITORY/docker-/}
|
||||||
|
set -x
|
||||||
if [[ $GITHUB_REF == refs/heads/* ]]; then
|
if [[ $GITHUB_REF == refs/heads/* ]]; then
|
||||||
if [[ $GITHUB_REF == refs/heads/*/* ]] ; then
|
if [[ $GITHUB_REF == refs/heads/*/* ]] ; then
|
||||||
BRANCH="${DOCKER_IMAGE}:$(echo $GITHUB_REF | sed "s|refs/heads/||g" | sed "s|/|-|g")"
|
BRANCH="${DOCKER_IMAGE}:$(echo $GITHUB_REF | sed "s|refs/heads/||g" | sed "s|/|-|g")"
|
||||||
|
|||||||
24
CHANGELOG.md
24
CHANGELOG.md
@@ -1,27 +1,3 @@
|
|||||||
## 3.6.0 2022-11-21 <dave at tiredofit dot ca>
|
|
||||||
|
|
||||||
### Added
|
|
||||||
- Postgresql 15 Support
|
|
||||||
|
|
||||||
|
|
||||||
## 3.5.6 2022-11-15 <dave at tiredofit dot ca>
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- Add failure if DB_TYPE empty or malformed
|
|
||||||
|
|
||||||
|
|
||||||
## 3.5.5 2022-10-18 <dave at tiredofit dot ca>
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- Fix for S3 backups and trailing slashes (@greena13)
|
|
||||||
|
|
||||||
|
|
||||||
## 3.5.4 2022-10-13 <dave at tiredofit dot ca>
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- Fix for Influx DB 1 backups when compression enabled
|
|
||||||
|
|
||||||
|
|
||||||
## 3.5.3 2022-10-12 <dave at tiredofit dot ca>
|
## 3.5.3 2022-10-12 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
106
Dockerfile
106
Dockerfile
@@ -2,6 +2,7 @@ FROM docker.io/tiredofit/alpine:3.16
|
|||||||
LABEL maintainer="Dave Conroy (github.com/tiredofit)"
|
LABEL maintainer="Dave Conroy (github.com/tiredofit)"
|
||||||
|
|
||||||
### Set Environment Variables
|
### Set Environment Variables
|
||||||
|
|
||||||
ENV INFLUX2_VERSION=2.4.0 \
|
ENV INFLUX2_VERSION=2.4.0 \
|
||||||
MSSQL_VERSION=18.0.1.1-1 \
|
MSSQL_VERSION=18.0.1.1-1 \
|
||||||
CONTAINER_ENABLE_MESSAGING=FALSE \
|
CONTAINER_ENABLE_MESSAGING=FALSE \
|
||||||
@@ -10,105 +11,8 @@ ENV INFLUX2_VERSION=2.4.0 \
|
|||||||
IMAGE_NAME="tiredofit/db-backup" \
|
IMAGE_NAME="tiredofit/db-backup" \
|
||||||
IMAGE_REPO_URL="https://github.com/tiredofit/docker-db-backup/"
|
IMAGE_REPO_URL="https://github.com/tiredofit/docker-db-backup/"
|
||||||
|
|
||||||
ENV LANG=en_US.utf8 \
|
|
||||||
PG_MAJOR=15 \
|
|
||||||
PG_VERSION=15.1 \
|
|
||||||
PGDATA=/var/lib/postgresql/data
|
|
||||||
|
|
||||||
### Create User Accounts
|
|
||||||
RUN set -ex && \
|
|
||||||
addgroup -g 70 postgres && \
|
|
||||||
adduser -S -D -H -h /var/lib/postgresql -s /bin/sh -G postgres -u 70 postgres && \
|
|
||||||
mkdir -p /var/lib/postgresql && \
|
|
||||||
chown -R postgres:postgres /var/lib/postgresql && \
|
|
||||||
\
|
|
||||||
### Install Dependencies
|
|
||||||
apk update && \
|
|
||||||
apk upgrade && \
|
|
||||||
apk add \
|
|
||||||
openssl \
|
|
||||||
&& \
|
|
||||||
\
|
|
||||||
apk add --no-cache --virtual .postgres-build-deps \
|
|
||||||
bison \
|
|
||||||
build-base \
|
|
||||||
coreutils \
|
|
||||||
dpkg-dev \
|
|
||||||
dpkg \
|
|
||||||
flex \
|
|
||||||
gcc \
|
|
||||||
icu-dev \
|
|
||||||
libc-dev \
|
|
||||||
libedit-dev \
|
|
||||||
libxml2-dev \
|
|
||||||
libxslt-dev \
|
|
||||||
linux-headers \
|
|
||||||
make \
|
|
||||||
openssl-dev \
|
|
||||||
perl-utils \
|
|
||||||
perl-ipc-run \
|
|
||||||
util-linux-dev \
|
|
||||||
wget \
|
|
||||||
zlib-dev \
|
|
||||||
&& \
|
|
||||||
\
|
|
||||||
### Build Postgresql
|
|
||||||
mkdir -p /usr/src/postgresql && \
|
|
||||||
curl -sSL "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" | tar xvfj - --strip 1 -C /usr/src/postgresql && \
|
|
||||||
cd /usr/src/postgresql && \
|
|
||||||
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
|
|
||||||
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
|
|
||||||
awk '$1 == "#define" && $2 == "DEFAULT_PGSOCKET_DIR" && $3 == "\"/tmp\"" { $3 = "\"/var/run/postgresql\""; print; next } { print }' src/include/pg_config_manual.h > src/include/pg_config_manual.h.new && \
|
|
||||||
grep '/var/run/postgresql' src/include/pg_config_manual.h.new && \
|
|
||||||
mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h && \
|
|
||||||
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" && \
|
|
||||||
# explicitly update autoconf config.guess and config.sub so they support more arches/libcs
|
|
||||||
wget --inet4-only -O config/config.guess 'https://git.savannah.gnu.org/cgit/config.git/plain/config.guess?id=7d3d27baf8107b630586c962c057e22149653deb' && \
|
|
||||||
wget --inet4-only -O config/config.sub 'https://git.savannah.gnu.org/cgit/config.git/plain/config.sub?id=7d3d27baf8107b630586c962c057e22149653deb' && \
|
|
||||||
./configure \
|
|
||||||
--build="$gnuArch" \
|
|
||||||
--enable-integer-datetimes \
|
|
||||||
--enable-thread-safety \
|
|
||||||
--enable-tap-tests \
|
|
||||||
--disable-rpath \
|
|
||||||
--with-uuid=e2fs \
|
|
||||||
--with-gnu-ld \
|
|
||||||
--with-pgport=5432 \
|
|
||||||
--with-system-tzdata=/usr/share/zoneinfo \
|
|
||||||
--prefix=/usr/local \
|
|
||||||
--with-includes=/usr/local/include \
|
|
||||||
--with-libraries=/usr/local/lib \
|
|
||||||
--with-openssl \
|
|
||||||
--with-libxml \
|
|
||||||
--with-libxslt \
|
|
||||||
--with-icu \
|
|
||||||
&& \
|
|
||||||
\
|
|
||||||
make -j "$(nproc)" world && \
|
|
||||||
make install-world && \
|
|
||||||
make -C contrib install && \
|
|
||||||
runDeps="$( \
|
|
||||||
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
|
|
||||||
| tr ',' '\n' \
|
|
||||||
| sort -u \
|
|
||||||
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
|
|
||||||
)" && \
|
|
||||||
apk add -t .postgres-additional-deps \
|
|
||||||
$runDeps \
|
|
||||||
&& \
|
|
||||||
\
|
|
||||||
### Cleanup
|
|
||||||
apk del .postgres-build-deps && \
|
|
||||||
cd / && \
|
|
||||||
rm -rf \
|
|
||||||
/usr/src/postgresql \
|
|
||||||
/usr/local/share/doc \
|
|
||||||
/usr/local/share/man && \
|
|
||||||
find /usr/local -name '*.a' -delete && \
|
|
||||||
rm -rf /var/cache/apk/* && \
|
|
||||||
\
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
set -ex && \
|
RUN set -ex && \
|
||||||
apk update && \
|
apk update && \
|
||||||
apk upgrade && \
|
apk upgrade && \
|
||||||
apk add -t .db-backup-build-deps \
|
apk add -t .db-backup-build-deps \
|
||||||
@@ -133,8 +37,8 @@ RUN set -ex && \
|
|||||||
mongodb-tools \
|
mongodb-tools \
|
||||||
libressl \
|
libressl \
|
||||||
pigz \
|
pigz \
|
||||||
#postgresql \
|
postgresql \
|
||||||
#postgresql-client \
|
postgresql-client \
|
||||||
pv \
|
pv \
|
||||||
py3-cryptography \
|
py3-cryptography \
|
||||||
redis \
|
redis \
|
||||||
@@ -179,4 +83,4 @@ RUN set -ex && \
|
|||||||
rm -rf /root/.cache /tmp/* /var/cache/apk/*
|
rm -rf /root/.cache /tmp/* /var/cache/apk/*
|
||||||
|
|
||||||
### S6 Setup
|
### S6 Setup
|
||||||
COPY install /
|
ADD install /
|
||||||
|
|||||||
24
README.md
24
README.md
@@ -189,19 +189,19 @@ Your Organization will be mapped to `DB_USER` and your root token will need to b
|
|||||||
|
|
||||||
If `BACKUP_LOCATION` = `S3` then the following options are used.
|
If `BACKUP_LOCATION` = `S3` then the following options are used.
|
||||||
|
|
||||||
| Parameter | Description | Default |
|
| Parameter | Description | Default |
|
||||||
|-----------------------|------------------------------------------------------------------------------------------|---------|
|
|-----------------------|-------------------------------------------------------------------------------------------|---------|
|
||||||
| `S3_BUCKET` | S3 Bucket name e.g. `mybucket` | |
|
| `S3_BUCKET` | S3 Bucket name e.g. `mybucket` | |
|
||||||
| `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 (must NOT end in a trailing slash e.g. '`backup`') | |
|
| `S3_PATH` | S3 Pathname to save to (must end in a trailing slash e.g. '`backup/`') | |
|
||||||
| `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_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`. | `https` |
|
| `S3_PROTOCOL` | Protocol to connect to `S3_HOST`. Either `http` or `https`. Defaults to `https`. | `https` |
|
||||||
| `S3_EXTRA_OPTS` | Add any extra options to the end of the `aws-cli` process execution | |
|
| `S3_EXTRA_OPTS` | Add any extra options to the end of the `aws-cli` process execution | |
|
||||||
| `S3_CERT_CA_FILE` | Map a volume and point to your custom CA Bundle for verification e.g. `/certs/bundle.pem` | |
|
| `S3_CERT_CA_FILE` | Map a volume and point to your custom CA Bundle for verification e.g. `/certs/bundle.pem` | |
|
||||||
| _*OR*_ | | |
|
| _*OR*_ | | |
|
||||||
| `S3_CERT_SKIP_VERIFY` | Skip verifying self signed certificates when connecting | `TRUE` |
|
| `S3_CERT_SKIP_VERIFY` | Skip verifying self signed certificates when connecting | `TRUE` |
|
||||||
|
|
||||||
#### Upload to a Azure storage account by `blobxfer`
|
#### Upload to a Azure storage account by `blobxfer`
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#!/command/with-contenv bash
|
#!/command/with-contenv bash
|
||||||
|
|
||||||
bootstrap_variables() {
|
bootstrap_variables() {
|
||||||
sanity_var DB_TYPE "Set appropriate DB_TYPE"
|
|
||||||
case "${DB_TYPE,,}" in
|
case "${DB_TYPE,,}" in
|
||||||
couch* )
|
couch* )
|
||||||
dbtype=couch
|
dbtype=couch
|
||||||
@@ -75,10 +74,6 @@ bootstrap_variables() {
|
|||||||
sqlite* )
|
sqlite* )
|
||||||
dbtype=sqlite3
|
dbtype=sqlite3
|
||||||
;;
|
;;
|
||||||
* )
|
|
||||||
print_error "I don't recognize 'DB_TYPE=${DB_TYPE}' - Exitting.."
|
|
||||||
exit 99
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ "${BACKUP_LOCATION,,}" = "s3" ] || [ "${BACKUP_LOCATION,,}" = "minio" ] ; then
|
if [ "${BACKUP_LOCATION,,}" = "s3" ] || [ "${BACKUP_LOCATION,,}" = "minio" ] ; then
|
||||||
@@ -121,7 +116,7 @@ backup_influx() {
|
|||||||
influxd backup ${influx_compression} ${bucket} -portable -host ${DB_HOST}:${DB_PORT} ${EXTRA_OPTS} "${TEMP_LOCATION}"/"${target_dir}"
|
influxd backup ${influx_compression} ${bucket} -portable -host ${DB_HOST}:${DB_PORT} ${EXTRA_OPTS} "${TEMP_LOCATION}"/"${target_dir}"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code $target_dir
|
check_exit_code $target_dir
|
||||||
print_notice "Creating archive file of '${target_dir}' with tar ${compression_string}"
|
print_notice "Creating archive file of '${target_dir}' with tar ${compresion_string}"
|
||||||
tar cf - "${TEMP_LOCATION}"/"${target_dir}" | $dir_compress_cmd > "${TEMP_LOCATION}"/"${target_dir}".tar"${extension}"
|
tar cf - "${TEMP_LOCATION}"/"${target_dir}" | $dir_compress_cmd > "${TEMP_LOCATION}"/"${target_dir}".tar"${extension}"
|
||||||
target=influx_${db}_${DB_HOST#*//}_${now}.tar${extension}
|
target=influx_${db}_${DB_HOST#*//}_${now}.tar${extension}
|
||||||
generate_checksum
|
generate_checksum
|
||||||
@@ -476,7 +471,7 @@ cleanup_old_data() {
|
|||||||
;;
|
;;
|
||||||
"s3" | "minio" )
|
"s3" | "minio" )
|
||||||
print_info "Cleaning up old backups on S3 storage"
|
print_info "Cleaning up old backups on S3 storage"
|
||||||
aws ${PARAM_AWS_ENDPOINT_URL} s3 ls s3://${S3_BUCKET}/${S3_PATH}/ ${s3_ssl} ${s3_ca_cert} ${S3_EXTRA_OPTS} | grep " DIR " -v | grep " PRE " -v | while read -r s3_file; do
|
aws ${PARAM_AWS_ENDPOINT_URL} s3 ls s3://${S3_BUCKET}/${S3_PATH} ${s3_ssl} ${s3_ca_cert} ${S3_EXTRA_OPTS} | grep " DIR " -v | grep " PRE " -v | while read -r s3_file; do
|
||||||
s3_createdate=$(echo $s3_file | awk {'print $1" "$2'})
|
s3_createdate=$(echo $s3_file | awk {'print $1" "$2'})
|
||||||
s3_createdate=$(date -d "$s3_createdate" "+%s")
|
s3_createdate=$(date -d "$s3_createdate" "+%s")
|
||||||
s3_olderthan=$(echo $(( $(date +%s)-${DB_CLEANUP_TIME}*60 )))
|
s3_olderthan=$(echo $(( $(date +%s)-${DB_CLEANUP_TIME}*60 )))
|
||||||
@@ -484,7 +479,7 @@ cleanup_old_data() {
|
|||||||
s3_filename=$(echo $s3_file | awk {'print $4'})
|
s3_filename=$(echo $s3_file | awk {'print $4'})
|
||||||
if [ "$s3_filename" != "" ] ; then
|
if [ "$s3_filename" != "" ] ; then
|
||||||
print_debug "Deleting $s3_filename"
|
print_debug "Deleting $s3_filename"
|
||||||
silent aws ${PARAM_AWS_ENDPOINT_URL} s3 rm s3://${S3_BUCKET}/${S3_PATH}/${s3_filename} ${s3_ssl} ${s3_ca_cert} ${S3_EXTRA_OPTS}
|
silent aws ${PARAM_AWS_ENDPOINT_URL} s3 rm s3://${S3_BUCKET}/${S3_PATH}${s3_filename} ${s3_ssl} ${s3_ca_cert} ${S3_EXTRA_OPTS}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user