I'm running a Meteor application using MUP for deployment. So on the server I created a backup-script, which looks like this:
#!/bin/sh
#export mongodump
docker exec -it mongodb mongodump --archive=/root/mongodump.gz --gzip
#create datestring
filedate=$(date +%Y-%m-%d_%H-%M-%S)
#put dump export in file
docker cp mongodb:/root/mongodump.gz mongodump_$filedate.gz
All good so far and all works as expected.
The weird problem starts when I add the script to a cronjob
0 1 * * * /home/user1/backup.sh
This also works, i.e. the mongodump.gz
is added properly. However, for any reason the backup is always the same (matching SHA-256-HASH) as long as the cronjob creates the backup. When I run the backup script manually again, SHA-Hash and filesize of the dump changes. The next time the cronjob backup is called, it is the same as the previous created backup.
Any ideas what's happening here?
It's difficult to say what might be going wrong in your backup script, but for the same setup (backing up a mup-deployed meteor database via a cronjob), I use this script and it works well:
#!/bin/bash
# fail on error
set -e
# NOTE: no -it in docker command, see
# https://stackoverflow.com/questions/43099116/error-the-input-device-is-not-a-tty
docker exec mongodb mongodump -d mydb -o /data/db/ --gzip -- -j 1
mkdir -p /home/ubuntu/backup/
sudo rm -rf /home/ubuntu/backup/mydb
sudo mv /var/lib/mongodb/mydb /home/ubuntu/backup
sudo chown ubuntu:ubuntu -R /home/ubuntu/backup/mydb
A couple of things to note:
-it
from the docker command to avoid issues with the terminal not being a tty, see here.docker cp
, since mup uses a persistent folder inside the container that can be accessed from the host directly.