-
Notifications
You must be signed in to change notification settings - Fork 101
/
backups.js
168 lines (165 loc) · 5.22 KB
/
backups.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* Copyright 2024 Google LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const {createBackup} = require('./backups-create');
const {
createBackupWithEncryptionKey,
} = require('./backups-create-with-encryption-key');
const {cancelBackup} = require('./backups-cancel');
const {getBackups} = require('./backups-get');
const {getBackupOperations} = require('./backups-get-operations');
const {getDatabaseOperations} = require('./backups-get-database-operations');
const {updateBackup} = require('./backups-update');
const {restoreBackup} = require('./backups-restore');
const {
restoreBackupWithEncryptionKey,
} = require('./backups-restore-with-encryption-key');
const {deleteBackup} = require('./backups-delete');
require('yargs')
.demand(1)
.command(
'createBackup <instanceName> <databaseName> <backupName> <projectId> <versionTime>',
'Creates a backup of a Cloud Spanner database.',
{},
opts =>
createBackup(
opts.instanceName,
opts.databaseName,
opts.backupName,
opts.projectId,
Date.parse(opts.versionTime)
)
)
.example(
'node $0 createBackup "my-instance" "my-database" "my-backup" "my-project-id" "my-version-time"'
)
.command(
'createBackupWithEncryptionKey <instanceName> <databaseName> <backupName> <projectId> <keyName>',
'Creates a backup of a Cloud Spanner database using an encryption key.',
{},
opts =>
createBackupWithEncryptionKey(
opts.instanceName,
opts.databaseName,
opts.backupName,
opts.projectId,
opts.keyName
)
)
.example(
'node $0 createBackupWithEncryptionKey "my-instance" "my-database" "my-backup" "my-project-id" "my-key-name"'
)
.command(
'cancelBackup <instanceName> <databaseName> <backupName> <projectId>',
'Creates and cancels a backup of a Cloud Spanner database.',
{},
opts =>
cancelBackup(
opts.instanceName,
opts.databaseName,
opts.backupName,
opts.projectId
)
)
.example(
'node $0 cancelBackup "my-instance" "my-database" "my-backup" "my-project-id"'
)
.command(
'getBackups <instanceName> <databaseName> <backupName> <projectId>',
'Lists backups in the instance with filters.',
{},
opts =>
getBackups(
opts.instanceName,
opts.databaseName,
opts.backupName,
opts.projectId
)
)
.example(
'node $0 getBackups "my-instance" "my-database" "my-backup" "my-project-id"'
)
.command(
'getBackupOperations <instanceName> <databaseName> <backupName> <projectId>',
'Lists all backup operations in the instance.',
{},
opts =>
getBackupOperations(
opts.instanceName,
opts.databaseName,
opts.backupName,
opts.projectId
)
)
.example(
'node $0 getBackupOperations "my-instance" "my-database" "my-backup" "my-project-id"'
)
.command(
'getDatabaseOperations <instanceName> <projectId>',
'Lists all database operations in the instance.',
{},
opts => getDatabaseOperations(opts.instanceName, opts.projectId)
)
.example('node $0 getDatabaseOperations "my-instance" "my-project-id"')
.command(
'updateBackup <instanceName> <backupName> <projectId>',
'Updates the expire time of a backup.',
{},
opts => updateBackup(opts.instanceName, opts.backupName, opts.projectId)
)
.example('node $0 updateBackup "my-instance" "my-backup" "my-project-id"')
.command(
'restoreBackup <instanceName> <databaseName> <backupName> <projectId>',
'Restores a Cloud Spanner database from a backup.',
{},
opts =>
restoreBackup(
opts.instanceName,
opts.databaseName,
opts.backupName,
opts.projectId
)
)
.example(
'node $0 restoreBackup "my-instance" "my-database" "my-backup" "my-project-id"'
)
.command(
'restoreBackupWithEncryptionKey <instanceName> <databaseName> <backupName> <projectId> <keyName>',
'Restores a Cloud Spanner database from a backup with an encryption key.',
{},
opts =>
restoreBackupWithEncryptionKey(
opts.instanceName,
opts.databaseName,
opts.backupName,
opts.projectId,
opts.keyName
)
)
.example(
'node $0 restoreBackupWithEncryptionKey "my-instance" "my-database" "my-backup" "my-project-id" "my-key-name"'
)
.command(
'deleteBackup <instanceName> <backupName> <projectId>',
'Deletes a backup.',
{},
opts => deleteBackup(opts.instanceName, opts.backupName, opts.projectId)
)
.example('node $0 deleteBackup "my-instance" "my-backup" "my-project-id"')
.wrap(120)
.recommendCommands()
.epilogue('For more information, see https://cloud.google.com/spanner/docs')
.strict()
.help().argv;