https://github.com/ishanjain28/s3-mongo-backup
Mongodb backups to S3
https://github.com/ishanjain28/s3-mongo-backup
aws aws-s3 backup backup-script mongodb nodejs nodejs-modules s3
Last synced: 5 months ago
JSON representation
Mongodb backups to S3
- Host: GitHub
- URL: https://github.com/ishanjain28/s3-mongo-backup
- Owner: ishanjain28
- License: mit
- Created: 2017-04-07T16:58:37.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-03-09T14:30:26.000Z (about 3 years ago)
- Last Synced: 2025-09-13T15:15:13.298Z (9 months ago)
- Topics: aws, aws-s3, backup, backup-script, mongodb, nodejs, nodejs-modules, s3
- Language: JavaScript
- Size: 87.9 KB
- Stars: 19
- Watchers: 4
- Forks: 20
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# s3-mongo-backup
This Module Helps in automating mongodb database Backups and uploading them to AWS S3.
# Features
- Supports Promises
- Uploads Backups to S3 in "mongoDbBackups" folder
- Uses GZip Compression to reduce Backup Size
# Usage
## Import
```javascript
const MBackup = require('s3-mongo-backup');
```
## Create a configuration Object
```javascript
var backupConfig = {
mongodb: "mongodb://username:password@localhost:27017", // MongoDB Connection URI
s3: {
accessKey: "", //AccessKey
secretKey: "", //SecretKey
region: "", //S3 Bucket Region
accessPerm: "private", //S3 Bucket Privacy, Since, You'll be storing Database, Private is HIGHLY Recommended
bucketName: "" //Bucket Name
},
keepLocalBackups: false, //If true, It'll create a folder in project root with database's name and store backups in it and if it's false, It'll use temporary directory of OS
noOfLocalBackups: 5, //This will only keep the most recent 5 backups and delete all older backups from local backup directory
timezoneOffset: 300 //Timezone, It is assumed to be in hours if less than 16 and in minutes otherwise
}
```
### Or
```javascript
var backupConfig = {
mongodb: {
"database": "freecodecamp",
"host": "localhost",
"username": "admin",
"password": "password",
"port": 27017
},
s3: {
accessKey: "", //AccessKey
secretKey: "", //SecretKey
region: "", //S3 Bucket Region
accessPerm: "private", //S3 Bucket Privacy, Since, You'll be storing Database, Private is HIGHLY Recommended
bucketName: "" //Bucket Name
},
keepLocalBackups: false, //If true, It'll create a folder in project root with database's name and store backups in it and if it's false, It'll use temporary directory of OS
noOfLocalBackups: 5, //This will only keep the most recent 5 backups and delete all older backups from local backup directory
timezoneOffset: 300 //Timezone, It is assumed to be in hours if less than 16 and in minutes otherwise
}
```
### Call the Function and provide Configuration Object to it.
```javascript
MBackup(backupConfig)
.then(
onResolve => {
// When everything was successful
console.log(onResolve);
},
onReject => {
// When Anything goes wrong!
console.log(onReject);
});
```
> See examples directory for more examples
### Timezone offset's Purpose
Database zip files are stored in format `{database_name}_{YYYY-MM-DDTHH:mm:ss}`. Here, If you don't provide a Timezone offset, It'll assume UTC timezone and name all the backups accordingly. Now, If something goes wrong at "2:00 PM" in your timezone and you need to restore a backup made at "1:00 PM" in your timezone, You'll have to change UTC time to your time and then see which backup you have to restore.
But If you provide a timezone of where ever you live, You can immdiately recognise which backup can be useful.
To see how to provide Timezone offset, Please refer to [moment#utcOffset](http://momentjs.com/docs/#/manipulating/utc-offset/)
# License
MIT
# Changelog
2.0.0 -> Uses MongoDB Connection URI directly, instead of asking for individual values of username, database name, password and database host.
## NOTE
1. This module uses `mongodump` to create backup of database, You need to have it installed on the machine on which you are using this module.
2. To restore the generated backups
```bash
mongorestore --host localhost --port=27017 --gzip --archive=\
```