Node MongoDB Backup
This project creates backups of Mongo DB collections on a set interval using node-cron.
Set up
-
git clone git@github.com:luke-rmaki/node_mongodb_backup.git
-
cd node_mongo_backup
-
npm install
oryarn install
-
Create a config.ts file, exporting the following information(see below for an example):
- Database URI (uri)
- Database name (dbName)
- Collection names (collections) -> This must be an array even if there is only one collection
-
Set a cron schedule in main.ts (see Crontab Guru for more help)
-
Install pm2
npm i -g pm2
-
Run
npm run deploy
oryarn deploy
Example config.ts file
module.exports.config = {
uri:
"mongodb+srv://<username>:<password>@database_url.mongodb.net/test?retryWrites=true&w=majority",
dbName: "database_name",
collections: ["collection_name", "collection_name_1"],
};