Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/improv #1

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.c

WORKDIR /openrm

RUN mkdir /backups
RUN mkdir -p /var/tmp/backups
RUN chmod 777 -R /var/tmp/backups
ADD script.sh /openrm/script.sh

VOLUME /backups
VOLUME /var/tmp/backups

ENTRYPOINT ["/openrm/script.sh"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This container is meant to be used as a cronjob with Kubernetes.
The service account running the container needs to have write access to the destination bucket, as this container makes use of `gsutil`.

# Volumes
You can mount a volume on `/backups` if you want to collect the intermediate archives, or give more space to your container for the backup process.
You can mount a volume on `/var/tmp/backups` if you want to collect the intermediate archives, or give more space to your container for the backup process.

# Cron Schedule Syntax

Expand Down
6 changes: 4 additions & 2 deletions script.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/bin/bash
set -eu

workdir=/var/tmp/backups
filename=$(date +'%Y%m%d-%H%M')-$RANDOM.tar.gz

echo "Exporting MongoDB data as $filename"

mongodump --uri ${MONGO_URI} --archive=/backups/$filename --gzip
mongodump --uri ${MONGO_URI} --archive=$workdir/$filename --gzip

echo "MongDB data exported, uploading $filename to GCS (gs://${GCS_BUCKET})"

gsutil -m mv /backups/$filename gs://${GCS_BUCKET}/
gsutil -m mv $workdir/$filename gs://${GCS_BUCKET}/

echo "Archive successfully $filename uploaded to gs://${GCS_BUCKET}"

Expand Down