Skip to content

Commit

Permalink
Merge pull request #57667 from pbardea/backport20.2-57656
Browse files Browse the repository at this point in the history
release-20.2: backupccl: properly support restoring cluster backups from collections
  • Loading branch information
pbardea authored Dec 7, 2020
2 parents 1c815f7 + 406861b commit 44fe5a3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/generated/sql/bnf/restore.bnf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
restore_stmt ::=
'RESTORE' 'FROM' list_of_string_or_placeholder_opt_list opt_as_of_clause opt_with_restore_options
| 'RESTORE' 'FROM' string_or_placeholder 'IN' list_of_string_or_placeholder_opt_list opt_as_of_clause opt_with_restore_options
| 'RESTORE' ( ( 'TABLE' | ) table_pattern ( ( ',' table_pattern ) )* | 'DATABASE' database_name ( ( ',' database_name ) )* ) 'FROM' list_of_string_or_placeholder_opt_list opt_as_of_clause opt_with_restore_options
| 'RESTORE' ( ( 'TABLE' | ) table_pattern ( ( ',' table_pattern ) )* | 'DATABASE' database_name ( ( ',' database_name ) )* ) 'FROM' string_or_placeholder 'IN' list_of_string_or_placeholder_opt_list opt_as_of_clause opt_with_restore_options
1 change: 1 addition & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ reset_stmt ::=

restore_stmt ::=
'RESTORE' 'FROM' list_of_string_or_placeholder_opt_list opt_as_of_clause opt_with_restore_options
| 'RESTORE' 'FROM' string_or_placeholder 'IN' list_of_string_or_placeholder_opt_list opt_as_of_clause opt_with_restore_options
| 'RESTORE' targets 'FROM' list_of_string_or_placeholder_opt_list opt_as_of_clause opt_with_restore_options
| 'RESTORE' targets 'FROM' string_or_placeholder 'IN' list_of_string_or_placeholder_opt_list opt_as_of_clause opt_with_restore_options

Expand Down
10 changes: 10 additions & 0 deletions pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,16 @@ func TestBackupRestoreAppend(t *testing.T) {

sqlDB.Exec(t, "DROP DATABASE data CASCADE")
sqlDB.Exec(t, "RESTORE DATABASE data FROM $4 IN ($1, $2, $3) AS OF SYSTEM TIME "+ts2, append(collections, fullBackup2)...)

if test.name != "userfile" {
// Cluster restores from userfile are not supported yet since the
// restoring cluster needs to be empty, which means it can't contain any
// userfile tables.

_, _, sqlDBRestore, cleanupEmptyCluster := backupRestoreTestSetupEmpty(t, MultiNode, tmpDir, InitNone)
defer cleanupEmptyCluster()
sqlDBRestore.Exec(t, "RESTORE FROM $4 IN ($1, $2, $3) AS OF SYSTEM TIME "+ts2, append(collections, fullBackup2)...)
}
}

if test.name == "userfile" {
Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,14 @@ func TestParse(t *testing.T) {
{`RESTORE DATABASE foo FROM ($1, $2), ($3, $4)`},
{`RESTORE DATABASE foo FROM ($1, $2), ($3, $4) AS OF SYSTEM TIME '1'`},

{`RESTORE FROM ($1, $2)`},
{`RESTORE FROM ($1, $2), $3`},
{`RESTORE FROM $1, ($2, $3)`},
{`RESTORE FROM ($1, $2), ($3, $4)`},
{`RESTORE FROM ($1, $2), ($3, $4) AS OF SYSTEM TIME '1'`},
{`RESTORE FROM $4 IN $1, $2, 'bar'`},
{`RESTORE FROM $4 IN $1, $2, 'bar' AS OF SYSTEM TIME '1' WITH skip_missing_foreign_keys`},

{`RESTORE TENANT 36 FROM ($1, $2) AS OF SYSTEM TIME '1'`},

{`BACKUP TABLE foo TO 'bar' WITH revision_history, detached`},
Expand Down
10 changes: 10 additions & 0 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -2447,6 +2447,16 @@ restore_stmt:
Options: *($5.restoreOptions()),
}
}
| RESTORE FROM string_or_placeholder IN list_of_string_or_placeholder_opt_list opt_as_of_clause opt_with_restore_options
{
$$.val = &tree.Restore{
DescriptorCoverage: tree.AllDescriptors,
Subdir: $3.expr(),
From: $5.listOfStringOrPlaceholderOptList(),
AsOf: $6.asOfClause(),
Options: *($7.restoreOptions()),
}
}
| RESTORE targets FROM list_of_string_or_placeholder_opt_list opt_as_of_clause opt_with_restore_options
{
$$.val = &tree.Restore{
Expand Down

0 comments on commit 44fe5a3

Please sign in to comment.