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:
5
docker/mongo-backup.cron
Normal file
5
docker/mongo-backup.cron
Normal 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
27
docker/mongo-backup.sh
Executable 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/
|
Reference in New Issue
Block a user