UNPKG

1.39 kBJavaScriptView Raw
1'use strict'
2
3const co = require('co')
4const cli = require('heroku-cli-util')
5
6function * run (context, heroku) {
7 const pgbackups = require('../../lib/pgbackups')(context, heroku)
8 const fetcher = require('../../lib/fetcher')(heroku)
9 const host = require('../../lib/host')
10
11 const {app, args, flags} = context
12 const interval = Math.max(3, parseInt(flags['wait-interval'])) || 3
13 const db = yield fetcher.addon(app, args.database)
14
15 let backup
16 yield cli.action(`Starting backup of ${cli.color.addon(db.name)}`, co(function * () {
17 backup = yield heroku.post(`/client/v11/databases/${db.name}/backups`, {host: host(db)})
18 }))
19 cli.log(`
20Use Ctrl-C at any time to stop monitoring progress; the backup will continue running.
21Use ${cli.color.cmd('heroku pg:backups:info')} to check progress.
22Stop a running backup with ${cli.color.cmd('heroku pg:backups:cancel')}.
23`)
24
25 yield pgbackups.wait(`Backing up ${cli.color.configVar(backup.from_name)} to ${cli.color.cyan(pgbackups.transfer.name(backup))}`, backup.uuid, interval, flags.verbose)
26}
27
28module.exports = {
29 topic: 'pg',
30 command: 'backups:capture',
31 description: 'capture a new backup',
32 needsApp: true,
33 needsAuth: true,
34 args: [{name: 'database', optional: true}],
35 flags: [
36 {name: 'wait-interval', hasValue: true},
37 {name: 'verbose', char: 'v'}
38 ],
39 run: cli.command({preauth: true}, co.wrap(run))
40}