Skip to content

Commit

Permalink
Master (#1)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Thiritin authored Mar 29, 2023
1 parent b2ba7e8 commit 49be6a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
20 changes: 9 additions & 11 deletions backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand All @@ -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"
Expand Down

0 comments on commit 49be6a0

Please sign in to comment.