Skip to content

Commit

Permalink
✨ MySQL Dump backup
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>
  • Loading branch information
mhkarimi1383 committed Nov 23, 2024
1 parent 4a8ed0c commit 2668b5c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backups/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,15 @@ FROM base-pg AS pg-dump

ENV BACKUP_CMD "/opt/parmincloud/backups/pg-dump"
COPY --chmod=0775 pg-dump.sh /opt/parmincloud/backups/pg-dump

FROM base AS mysql-dump

ENV BACKUP_CMD "/opt/parmincloud/backups/mysql-dump"
ENV DATA_DIR "/data"

ENV MYSQL_HOST ""
ENV MYSQL_PORT ""
ENV MYSQL_USER ""
ENV MYSQL_PASSWORD ""

COPY --chmod=0775 mysql-dump.sh /opt/parmincloud/backups/mysql-dump
36 changes: 36 additions & 0 deletions backups/mysql-dump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

set -o pipefail -ue

. /opt/parmincloud/backups/utils

if [ -z "$MYSQL_HOST" ]; then
log "You need to set the MYSQL_HOST environment variable."
exit 1
fi
if [ -z "$MYSQL_USER" ]; then
log "You need to set the MYSQL_USER environment variable."
exit 1
fi
if [ -z "$MYSQL_PORT" ]; then
log "You need to set the MYSQL_PORT environment variable."
exit 1
fi
if [ -z "$MYSQL_PASSWORD" ]; then
log "You need to set the MYSQL_PASSWORD environment variable."
exit 1
fi

BACKUP_OUT=/tmp/dump.sql.gz

log "Creating dump of database"
mysqldump \
--host="${MYSQL_HOST}" \
--port="${MYSQL_PORT}" \
--password="${MYSQL_PASSWORD}" \
--user="${MYSQL_USER}" \
--single-transaction \
--get-server-public-key \
--all-databases | gzip -9 > "${BACKUP_OUT}"

echo "${BACKUP_OUT}"

0 comments on commit 2668b5c

Please sign in to comment.