Backup script for meteor mongodb
This is a mix of several backup utilities collected from the community and packaged for easy deployment on EC2 (or other).
This script can easily download the contents of your meteor database and upload it to S3. It is designed to work well with hosting on meteor.com as well as private meteor deployments. And with a one small adjustments it is easy to make it work for generic mongo databases backups, not just meteor specific.
Set up a host to run the backup. In this example we show how to set up a micro EC2 host that'll run the nightly backups but of cousrse you may use any other hosting service or even your own laptop or PC.
- Create an S3 bucket for the backup, eg
my-perfect-backup
- For increased security we're using an instance IAM role, which lets us get away from storing actual AWS credentials on the host itself. AWS will take care of providing short lived one-time credentials to the
s3cmd
tool when it needs them. Create a role named MeteorMongoBackup. The Role Type should be Amazon EC2, next click on Custom Policy and insert the contents of the fileMeteorMongoBackupRole.json
(replacingmy-perfect-backup
with your own bucket name from step 0) - Boot up an EC2 micro instance (a micro should be enough). When you create this instance make sure you select
MeteorMongoBackup
as the instance role. This will allow the host to seamlessly access your S3 bucket without needing to hardcode your AWS credentials on it.
- Once the host is running, ssh to this host and run the
setup.sh
script. Note that this script contains many sections (some of them are optional) so my suggestion is that you read it and run each line manually. - Edit the file
backup.sh
to update theSITE
URL and theCOLLECTIONS
. TheCOLLECTIONS
is only needed if you want to crate cleartext (json) backups using themeteor-backup
tool. If you're only interested in binary backups (bson) usingmongodump
then no need to specify the collections, they will all be backed up automatically, in binary format. json backups are useful for diffing or looking at just one collection's data, or grepping through them, but they also consume some more space. - Next, test the
backup.sh
script by running/bin/bash backup.sh
- Set up a cron job by running
crontab -e
and adding the contents of thecrontab
file from this repository
If you're having troubles try following these steps:
- Run
backup.sh
outside of cron and check if it's successful. You should seeDONE
at the end and no errors in betweem. - If cron gives you hard time you can try to debug it by first running it every minute and then inspecting syslog when it runs. To run every minute use the following cron string
* * * * *
(instead of0 0 * * *
). Now tail syslog and wait for cron to run:tail -f /var/log/syslog
. Don't forget to update the cron string when you're done such that it won't run every minute forever...
This simple setup is useful to backup meteor.com installation.
In case you'd like to backup other mongo installationas you might need just a subset of these, for example you will likely have the username/password provided, rather than having to run meteor mongo --url
and sed
to get the credentials.