-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd-backup.js
67 lines (54 loc) · 1.66 KB
/
cmd-backup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { BackupTarget, BackupSource, BackupSet, BackupOptions } = require('./lib');
const { memstats } = require('./lib/debug');
class Backup {
static async exec(args) {
// Parse backup options
const opts = (new BackupOptions({
setname: 'default',
sources: [],
backup: true,
})).parse(args);
// Configure backup from options
const { setname, sources, backup, verify, compare, fast, fstype, verbose, terse, destination, accessKey, checkHash } = opts;
const target = new BackupTarget({ destination, fast, fstype, verbose, accessKey });
await target.connect(opts.backup);
// login
accessKey && await target.login();
// Clean backup destination
if (opts.clean) {
await target.clean();
}
// Setup backup set
const backupset = new BackupSet({
setname,
verbose,
sources: backup && sources.map
(source => new BackupSource({
src: source.src,
filters: source.filters,
subdirs: source.subdirs,
verbose,
terse,
checkHash
})),
});
// Run the backup job
if (backup) await target.backup({ backupset, ...opts });
// If asked to verify, verify
if (verify) {
await target.verify({
compare, verbose, setname,
when: opts.backup ? 'running' : (opts.when || 'current')
});
}
// Finally, if backing up, complete the job (bake it)
if (opts.backup) await target.complete({ backupset, ...opts });
// logout
accessKey && await target.logout();
// cleanup
target.destroy();
// dump memory stats
if (verbose) memstats();
}
};
module.exports = Backup;