UNPKG

1.6 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.id}/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 if (app !== db.app.name) {
25 cli.log(`HINT: You are running this command with a non-billing application.
26Use ${cli.color.cmd('heroku pg:backups -a ' + db.app.name)} to check the list of backups.
27`)
28 }
29
30 yield pgbackups.wait(`Backing up ${cli.color.configVar(backup.from_name)} to ${cli.color.cyan(pgbackups.transfer.name(backup))}`, backup.uuid, interval, flags.verbose, db.app.name)
31}
32
33module.exports = {
34 topic: 'pg',
35 command: 'backups:capture',
36 description: 'capture a new backup',
37 needsApp: true,
38 needsAuth: true,
39 args: [{name: 'database', optional: true}],
40 flags: [
41 {name: 'wait-interval', hasValue: true},
42 {name: 'verbose', char: 'v'}
43 ],
44 run: cli.command({preauth: true}, co.wrap(run))
45}