From 49be6a0c642a4db7d297d10ddd736a0084da343a Mon Sep 17 00:00:00 2001 From: Tin Date: Wed, 29 Mar 2023 02:49:45 +0200 Subject: [PATCH] Master (#1) * add * push dockerfile * push dockerfile * untrack files contained in the .gitignore file * add backup script * remove dupelicated code * update backup script * fix build * fix build --- Dockerfile | 14 ++++++++++---- backup.sh | 20 +++++++++----------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 383eabb..835697e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,10 +16,16 @@ RUN curl https://dl.min.io/client/mc/release/linux-amd64/mc \ -o /usr/bin/mc \ && chmod +x /usr/bin/mc RUN groupadd --gid 1000 app \ - && adduser --uid 1000 --home /app --gid 1000 --disabled-password --gecos "" app \ - && chown app:app /app \ - && chmod 755 /app \ - && mkdir /app/backup + && adduser --uid 1000 --home /app --gid 1000 --disabled-password --gecos "" app USER app WORKDIR /app +RUN mkdir /app/backup + +## Add backup script +ADD ./backup.sh /app/backup.sh + +USER root +RUN chown -R app:app /app \ + && chmod -R 755 /app \ +USER app CMD ["/bin/bash","-c","/app/backup.sh"] \ No newline at end of file diff --git a/backup.sh b/backup.sh index 9cef059..9dc668f 100755 --- a/backup.sh +++ b/backup.sh @@ -2,39 +2,38 @@ set -e # Define the status update URL +# shellcheck disable=SC2153 status_url=${STATUS_URL} -trap "curl -fs '$status_url?status=down&msg=FAILED'" ERR +if [ -n "$status_url" ]; then + # shellcheck disable=SC2064 + trap "curl -fs '$status_url?status=down&msg=FAILED'" ERR +fi mkdir -p backup -# Define the backup filename -backup_filename="$BACKUP_SOURCE-$(date +%Y%m%d%H%M%S)" - # Check the backup source and run the appropriate backup client case $BACKUP_SOURCE in POSTGRES) - pbc_namespace=elbgoods/prg/crewzone - psql -tc "SELECT datname FROM pg_database WHERE datistemplate = false AND (datname LIKE 'dev_%' OR datname LIKE 'staging_%' OR datname LIKE 'production_%');" | while read database; do + psql -tc "$PG_DB_SELECT" | while read database; do echo "Backing up $database" # database is not empty if [ -n "$database" ]; then # Use the pg_dump tool to create a backup of the database - pg_dump -Fd -v -d $database -j 4 -Z0 -f ./backup/$database + pg_dump -Fd -v -d "$database" -j 4 -Z0 -f "./backup/$database" fi done ;; MINIO) - pbc_namespace=elbgoods/prg/crewzone # Use the minio client (mc) to create a backup of the bucket - mc alias set crewzone $S3_ENDPOINT $S3_ACCESS $S3_SECRET --api S3v4 + # shellcheck disable=SC2086 + mc alias set crewzone $S3_ENDPOINT "$S3_ACCESS" $S3_SECRET --api S3v4 # mirror each s3 bucket to a local directory mc ls crewzone | awk '{print $5}' | while read bucket; do mc mirror --overwrite crewzone/$bucket ./backup/$bucket done ;; MONGO) - pbc_namespace=elbgoods/prg/crewzone # Use the mongodump tool to create a backup of the database mongodump --uri "$MONGO_URL" --out=/app/backup ;; @@ -47,7 +46,6 @@ esac # Upload the backup to Proxmox backup client proxmox-backup-client backup $BACKUP_ID.pxar:/app/backup --backup-id $BACKUP_ID --ns $PBC_NAMESPACE --skip-lost-and-found - # Send a status update if [ -n "$status_url" ]; then curl -fs "$status_url?status=up&msg=OK"