https://github.com/theworkflow/mongodb-backup-cron
Backup mongo database on a cron schedule and send to AWS S3
https://github.com/theworkflow/mongodb-backup-cron
aws backup cli cron-schedule mongodb s3
Last synced: 2 months ago
JSON representation
Backup mongo database on a cron schedule and send to AWS S3
- Host: GitHub
- URL: https://github.com/theworkflow/mongodb-backup-cron
- Owner: theworkflow
- License: mit
- Created: 2017-04-07T15:05:16.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-09T14:50:26.000Z (about 9 years ago)
- Last Synced: 2026-04-30T12:34:46.258Z (2 months ago)
- Topics: aws, backup, cli, cron-schedule, mongodb, s3
- Language: JavaScript
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongodb-backup-cron
[][version]
[][build]
[][license]
> Backup mongo database on a cron schedule and send to AWS S3
## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [Contribute](#contribute)
- [License](#license)
## Install
To install globally
```
npm install mongodb-backup-cron --global
```
To install locally
```
npm install mongodb-backup-cron --save
```
## Usage
#### The mongo dump file is initially created in the operating system's temp directory using `OS.tmpdir()`
### CLI Usage
```
> mongodb-backup -h
Options:
--uri MongoDB uri [required]
--accessKeyId AWS access key id [required]
--secretAccessKey AWS secret access key [required]
--bucket AWS bucket (includes path to uploaded folder) [required]
--retry Number of retries for S3 upload
-h Show help [boolean]
```
### Module usage
To create a cron job
```js
const backup = require('mongodb-backup-cron')
const options = {
uri: 'mongodb://localhost:27017',
accessKeyId: 'key',
secretAccessKey: 'secret',
bucket: 'backup.mongo'
schedule: '0 0,12 * * *' // every 12 hours
}
const job = backup.cron(options)
```
To run a backup
```js
const { backup } = require('mongodb-backup-cron')
const options = {
uri: 'mongodb://localhost:27017/example',
accessKeyId: 'key',
secretAccessKey: 'secret',
bucket: 'backup.mongo'
}
backup(options, (err) => {
if (err) throw err
})
```
All options
```js
const options = {
uri: 'mongodb://localhost:27017/example',
accessKeyId: 'key',
secretAccessKey: 'secret',
bucket: 'backup.mongo',
retry: 3,
schedule: '0 0,12 * * *',
start: true, // used to specify if cron should start once created
timeZone: 'America/New_York'
}
```
### Configuration Files
Create [an rc file][rc] to set defaults, so you don't have to pass an
`uri`, `accessKeyId`, `secretAccessKey`, `retry`, and `bucket` flag to every command.
```
# ~/.mongodb-backuprc
uri = mongodb://localhost:27017/database
accessKeyId = key
secretAccessKey = secret
retry = 3
bucket = bucket
```
`mongodb-backup-cron` will walk the directory tree looking for rc files, so you can create
one in the root of your organization's project directory to make the CLI
context aware.
## License
[MIT © Jeremiah Harlan.](LICENSE)
[rc]: https://www.npmjs.com/package/rc
[version]: https://www.npmjs.com/package/mongodb-backup-cron
[build]: https://travis-ci.org/theworkflow/mongodb-backup-cron
[license]: https://raw.githubusercontent.com/theworkflow/mongodb-backup-cron/master/LICENSE