Skip to content

Commit

Permalink
backupccl: allow SHOW BACKUP FILES/RANGES/SCHEMAS in backup collections
Browse files Browse the repository at this point in the history
Fixes #77697

Release justification: low risk bug fixes

Release note: None
  • Loading branch information
msbutler committed Mar 18, 2022
1 parent cfe38f2 commit 71b8b0c
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/generated/sql/bnf/show_backup.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ show_backup_stmt ::=
| 'SHOW' 'BACKUP' 'SCHEMAS' location 'WITH' kv_option_list
| 'SHOW' 'BACKUP' 'SCHEMAS' location 'WITH' 'OPTIONS' '(' kv_option_list ')'
| 'SHOW' 'BACKUP' 'SCHEMAS' location
| 'SHOW' 'BACKUP' 'SCHEMAS' location 'IN' string_or_placeholder 'WITH' kv_option_list
| 'SHOW' 'BACKUP' 'SCHEMAS' location 'IN' string_or_placeholder 'WITH' 'OPTIONS' '(' kv_option_list ')'
| 'SHOW' 'BACKUP' 'SCHEMAS' location 'IN' string_or_placeholder
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 @@ -701,6 +701,7 @@ show_backup_stmt ::=
| 'SHOW' 'BACKUP' string_or_placeholder opt_with_options
| 'SHOW' 'BACKUP' string_or_placeholder 'IN' string_or_placeholder opt_with_options
| 'SHOW' 'BACKUP' 'SCHEMAS' string_or_placeholder opt_with_options
| 'SHOW' 'BACKUP' 'SCHEMAS' string_or_placeholder 'IN' string_or_placeholder opt_with_options

show_columns_stmt ::=
'SHOW' 'COLUMNS' 'FROM' table_name with_comment
Expand Down
45 changes: 45 additions & 0 deletions pkg/ccl/backupccl/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,51 @@ func TestShowBackups(t *testing.T) {

}

func TestShowNonDefaultBackups(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

const numAccounts = 11
_, sqlDB, _, cleanupFn := backupRestoreTestSetup(t, singleNode, numAccounts, InitManualReplication)
defer cleanupFn()

const full = localFoo + "/full"
const remoteInc = localFoo + "/inc"

// Make an initial backup.
fullNonDefault := full + "NonDefault"
incNonDefault := remoteInc + "NonDefault"
sqlDB.Exec(t, `BACKUP DATABASE data INTO $1`, fullNonDefault)

// Get base number of files, schemas, and ranges in the backup
var oldCount [3]int
for i, typ := range []string{"FILES", "SCHEMAS", "RANGES"} {
query := fmt.Sprintf(`SELECT count(*) FROM [SHOW BACKUP %s LATEST IN '%s']`, typ, fullNonDefault)
count, err := strconv.Atoi(sqlDB.QueryStr(t, query)[0][0])
require.NoError(t, err, "error converting original count to integer")
oldCount[i] = count
}

// Increase the number of files,schemas, and ranges that will be in the backup chain
sqlDB.Exec(t, `CREATE TABLE data.blob (a INT PRIMARY KEY); INSERT INTO data.blob VALUES (0)`)
sqlDB.Exec(t, `BACKUP INTO LATEST IN $1`, fullNonDefault)
sqlDB.Exec(t, `BACKUP INTO LATEST IN $1 WITH incremental_location=$2`, fullNonDefault, incNonDefault)

// Show backup should contain more rows as new files/schemas/ranges were
// added in the incremental backup
for i, typ := range []string{"FILES", "SCHEMAS", "RANGES"} {
query := fmt.Sprintf(`SELECT count(*) FROM [SHOW BACKUP %s LATEST IN '%s']`, typ, fullNonDefault)
newCount, err := strconv.Atoi(sqlDB.QueryStr(t, query)[0][0])
require.NoError(t, err, "error converting new count to integer")
require.Greater(t, newCount, oldCount[i])

queryInc := fmt.Sprintf(`SELECT count(*) FROM [SHOW BACKUP %s LATEST IN '%s' WITH incremental_location='%s']`, typ,
fullNonDefault, incNonDefault)
newCountInc, err := strconv.Atoi(sqlDB.QueryStr(t, queryInc)[0][0])
require.NoError(t, err, "error converting new count to integer")
require.Greater(t, newCountInc, oldCount[i])
}
}
func TestShowBackupTenants(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
Expand Down
30 changes: 30 additions & 0 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -5701,6 +5701,16 @@ show_backup_stmt:
Options: $5.kvOptions(),
}
}
| SHOW BACKUP SCHEMAS string_or_placeholder IN string_or_placeholder opt_with_options
{
$$.val = &tree.ShowBackup{
Details: tree.BackupDefaultDetails,
ShouldIncludeSchemas: true,
Path: $4.expr(),
InCollection: $6.expr(),
Options: $7.kvOptions(),
}
}
| SHOW BACKUP RANGES string_or_placeholder opt_with_options
{
/* SKIP DOC */
Expand All @@ -5710,6 +5720,16 @@ show_backup_stmt:
Options: $5.kvOptions(),
}
}
| SHOW BACKUP RANGES string_or_placeholder IN string_or_placeholder opt_with_options
{
/* SKIP DOC */
$$.val = &tree.ShowBackup{
Details: tree.BackupRangeDetails,
Path: $4.expr(),
InCollection: $6.expr(),
Options: $7.kvOptions(),
}
}
| SHOW BACKUP FILES string_or_placeholder opt_with_options
{
/* SKIP DOC */
Expand All @@ -5719,6 +5739,16 @@ show_backup_stmt:
Options: $5.kvOptions(),
}
}
| SHOW BACKUP FILES string_or_placeholder IN string_or_placeholder opt_with_options
{
/* SKIP DOC */
$$.val = &tree.ShowBackup{
Details: tree.BackupFileDetails,
Path: $4.expr(),
InCollection: $6.expr(),
Options: $7.kvOptions(),
}
}
| SHOW BACKUP error // SHOW HELP: SHOW BACKUP

// %Help: SHOW CLUSTER SETTING - display cluster settings
Expand Down
16 changes: 16 additions & 0 deletions pkg/sql/parser/testdata/backup_restore
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ SHOW BACKUP ('foo') IN ('bar') -- fully parenthesized
SHOW BACKUP '_' IN '_' -- literals removed
SHOW BACKUP 'foo' IN 'bar' -- identifiers removed

parse
SHOW BACKUP FILES 'foo' IN 'bar'
----
SHOW BACKUP FILES 'foo' IN 'bar'
SHOW BACKUP FILES ('foo') IN ('bar') -- fully parenthesized
SHOW BACKUP FILES '_' IN '_' -- literals removed
SHOW BACKUP FILES 'foo' IN 'bar' -- identifiers removed

parse
SHOW BACKUP RANGES 'foo' IN 'bar'
----
SHOW BACKUP RANGES 'foo' IN 'bar'
SHOW BACKUP RANGES ('foo') IN ('bar') -- fully parenthesized
SHOW BACKUP RANGES '_' IN '_' -- literals removed
SHOW BACKUP RANGES 'foo' IN 'bar' -- identifiers removed

parse
SHOW BACKUP $1 IN $2 WITH foo = 'bar'
----
Expand Down

0 comments on commit 71b8b0c

Please sign in to comment.