From 9742adc77e056a40a3ed1b79da39569929cf9994 Mon Sep 17 00:00:00 2001 From: Gensuke Toshiro Date: Thu, 19 May 2022 12:05:57 +0900 Subject: [PATCH 1/3] Allow non-root users --- script.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/script.sh b/script.sh index 3b3363c..87e5404 100755 --- a/script.sh +++ b/script.sh @@ -1,14 +1,15 @@ #!/bin/bash +workdir=/tmp 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}" From 2797c17fbff4751616acf8b03b9a158cb260684d Mon Sep 17 00:00:00 2001 From: Gensuke Toshiro Date: Thu, 19 May 2022 12:14:37 +0900 Subject: [PATCH 2/3] Set shell options --- script.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script.sh b/script.sh index 87e5404..15adfbd 100755 --- a/script.sh +++ b/script.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -eu workdir=/tmp filename=$(date +'%Y%m%d-%H%M')-$RANDOM.tar.gz From 818eb608e1e42f82313ae81ebefd013ae43638f8 Mon Sep 17 00:00:00 2001 From: Gensuke Toshiro Date: Fri, 16 Sep 2022 14:04:46 +0900 Subject: [PATCH 3/3] Use /var/tmp/backups instead --- Dockerfile | 5 +++-- README.md | 2 +- script.sh | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2d8cf8e..302f881 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 88acfb8..d9fdea9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/script.sh b/script.sh index 15adfbd..61b0892 100755 --- a/script.sh +++ b/script.sh @@ -1,7 +1,7 @@ #!/bin/bash set -eu -workdir=/tmp +workdir=/var/tmp/backups filename=$(date +'%Y%m%d-%H%M')-$RANDOM.tar.gz echo "Exporting MongoDB data as $filename"