Added script to run on server for nightly MongoDB backups

Forced to use IPv4 due to IPv6 connectivity issues with Swami.
This commit is contained in:
2018-02-06 11:00:40 +01:00
parent 6b56df9e9c
commit 2141aed06c
3 changed files with 33 additions and 1 deletions

View File

@@ -49,7 +49,7 @@ echo "==================================================================="
echo "Bringing remote Docker up to date…"
$SSH mkdir -p $REMOTE_DOCKER_COMPOSE_DIR
$SCP \
$DOCKER_DEPLOYDIR/$PROJECT_NAME/docker/{docker-compose.yml,renew-letsencrypt.sh} \
$DOCKER_DEPLOYDIR/$PROJECT_NAME/docker/{docker-compose.yml,renew-letsencrypt.sh,mongo-backup.{cron,sh}} \
$DEPLOYHOST:$REMOTE_DOCKER_COMPOSE_DIR
$SSH -T <<EOT
set -e

5
docker/mongo-backup.cron Normal file
View File

@@ -0,0 +1,5 @@
# Change to suit your needs, then place in /etc/cron.d/mongo-backup
# (so remove the .cron from the name)
MAILTO=yourname@youraddress.org
30 5 * * * root /root/docker/mongo-backup.sh

27
docker/mongo-backup.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/bash -e
BACKUPDIR=/data/storage/db-bak
DATE=$(date +'%Y-%m-%d-%H%M')
ARCHIVE=$BACKUPDIR/mongo-live-$DATE.tar.xz
# Just a sanity check before we give it to 'rm -rf'
if [ -z "$DATE" ]; then
echo "Empty string found where the date should be, aborting."
exit 1
fi
# /data/db-bak in Docker is /data/storage/db-bak on the host.
docker exec mongo mongodump -d cloud \
--out /data/db-bak/dump-$DATE \
--excludeCollection tokens \
--excludeCollection flamenco_task_logs \
--quiet
cd $BACKUPDIR
tar -Jcf $ARCHIVE dump-$DATE/
rm -rf dump-$DATE
rm -v $(ls $BACKUPDIR/mongo-live-*.tar.xz | head -n -7)
rsync -4 -va $BACKUPDIR/mongo-live-*.tar.xz cloud-backup@swami-direct.blender.cloud:/data/cloud-backup/