Skip to content

Commit

Permalink
backupccl: add deprecation notice to RESTORE FROM without subdir
Browse files Browse the repository at this point in the history
Informs: #78153

Release note (sql change): The `RESTORE FROM` syntax without an
explicit subdirectory pointing to a backup in a collection is deprecated,
and will be removed in a future release.
Users are recommended to use `RESTORE FROM <backup> IN <collection>` to
restore a particular backup in a collection.
  • Loading branch information
adityamaru committed Mar 22, 2022
1 parent 9118a0f commit 45288c7
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 34 deletions.
7 changes: 7 additions & 0 deletions pkg/ccl/backupccl/restore_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,13 @@ func restorePlanHook(
if err != nil {
return nil, nil, nil, false, err
}
} else {
// Deprecation notice for non-colelction `RESTORE FROM` syntax. Remove this
// once the syntax is deleted in 22.2.
p.BufferClientNotice(ctx,
pgnotice.Newf("Note the `RESTORE FROM <backup>` syntax will be removed in a future release, please"+
"switch over to using `RESTORE FROM <backup> IN <collection>` to restore a particular backup from a collection: %s",
"https://www.cockroachlabs.com/docs/stable/restore.html#view-the-backup-subdirectories"))
}

var incStorageFn func() ([]string, error)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/testdata/backup-restore/column-families
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ CREATE DATABASE r1;
----

exec-sql
RESTORE cfs FROM 'nodelocal://1/foo' WITH into_db='r1';
RESTORE cfs FROM LATEST IN 'nodelocal://1/foo' WITH into_db='r1';
----

query-sql
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/backupccl/testdata/backup-restore/feature-flags
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SET CLUSTER SETTING feature.restore.enabled = FALSE;
----

exec-sql
RESTORE TABLE d.t FROM 'nodelocal://0/test-root/';
RESTORE TABLE d.t FROM LATEST IN 'nodelocal://0/test-root/';
----
pq: feature RESTORE was disabled by the database administrator

Expand All @@ -46,5 +46,5 @@ SET CLUSTER SETTING feature.restore.enabled = TRUE;
----

exec-sql
RESTORE TABLE d.t FROM 'nodelocal://0/test-root/';
RESTORE TABLE d.t FROM LATEST IN 'nodelocal://0/test-root/';
----
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/testdata/backup-restore/max-row-size
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CREATE DATABASE d2;
----

exec-sql
RESTORE maxrow FROM 'nodelocal://1/maxrow' WITH into_db='d2';
RESTORE maxrow FROM LATEST IN 'nodelocal://1/maxrow' WITH into_db='d2';
----

query-sql
Expand Down
16 changes: 8 additions & 8 deletions pkg/ccl/backupccl/testdata/backup-restore/multiregion
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ new-server name=s2 share-io-dir=s1 allow-implicit-access localities=us-east-1,us
----

exec-sql
RESTORE FROM 'nodelocal://0/full_cluster_backup/';
RESTORE FROM LATEST IN 'nodelocal://0/full_cluster_backup/';
----

exec-sql
DROP DATABASE d;
----

exec-sql
RESTORE DATABASE d FROM 'nodelocal://0/database_backup/';
RESTORE DATABASE d FROM LATEST IN 'nodelocal://0/database_backup/';
----

query-sql
Expand All @@ -52,13 +52,13 @@ new-server name=s3 share-io-dir=s1 allow-implicit-access localities=eu-central-1
----

exec-sql
RESTORE DATABASE d FROM 'nodelocal://0/database_backup/';
RESTORE DATABASE d FROM LATEST IN 'nodelocal://0/database_backup/';
----
pq: detected a mismatch in regions between the restore cluster and the backup cluster, missing regions detected: us-east-1, us-west-1.
HINT: there are two ways you can resolve this issue: 1) update the cluster to which you're restoring to ensure that the regions present on the nodes' --locality flags match those present in the backup image, or 2) restore with the "skip_localities_check" option

exec-sql
RESTORE FROM 'nodelocal://0/full_cluster_backup/';
RESTORE FROM LATEST IN 'nodelocal://0/full_cluster_backup/';
----
pq: detected a mismatch in regions between the restore cluster and the backup cluster, missing regions detected: us-east-1, us-west-1.
HINT: there are two ways you can resolve this issue: 1) update the cluster to which you're restoring to ensure that the regions present on the nodes' --locality flags match those present in the backup image, or 2) restore with the "skip_localities_check" option
Expand Down Expand Up @@ -97,7 +97,7 @@ SET CLUSTER SETTING sql.defaults.primary_region = 'non-existent-region';
----

exec-sql
RESTORE DATABASE no_region_db FROM 'nodelocal://1/no_region_database_backup/';
RESTORE DATABASE no_region_db FROM LATEST IN 'nodelocal://1/no_region_database_backup/';
----
pq: region "non-existent-region" does not exist
HINT: valid regions: eu-central-1, eu-north-1
Expand All @@ -109,7 +109,7 @@ SET CLUSTER SETTING sql.defaults.primary_region = 'eu-central-1';
----

exec-sql
RESTORE DATABASE no_region_db FROM 'nodelocal://1/no_region_database_backup/';
RESTORE DATABASE no_region_db FROM LATEST IN 'nodelocal://1/no_region_database_backup/';
----
NOTICE: setting the PRIMARY REGION as eu-central-1 on database no_region_db
HINT: to change the default primary region, use SET CLUSTER SETTING sql.defaults.primary_region = 'region' or use RESET CLUSTER SETTING sql.defaults.primary_region to disable this behavior
Expand Down Expand Up @@ -148,7 +148,7 @@ SET CLUSTER SETTING sql.defaults.primary_region = 'eu-north-1';
----

exec-sql
RESTORE FROM 'nodelocal://1/no_region_cluster_backup/';
RESTORE FROM LATEST IN 'nodelocal://1/no_region_cluster_backup/';
----
NOTICE: setting the PRIMARY REGION as eu-north-1 on database defaultdb
HINT: to change the default primary region, use SET CLUSTER SETTING sql.defaults.primary_region = 'region' or use RESET CLUSTER SETTING sql.defaults.primary_region to disable this behavior
Expand Down Expand Up @@ -176,7 +176,7 @@ public t table root <nil> REGIONAL BY TABLE IN PRIMARY REGION

# Check we can restore without triggering the default primary region.
exec-sql
RESTORE DATABASE eu_central_db FROM 'nodelocal://1/eu_central_database_backup/';
RESTORE DATABASE eu_central_db FROM LATEST IN 'nodelocal://1/eu_central_database_backup/';
----

query-sql
Expand Down
10 changes: 5 additions & 5 deletions pkg/ccl/backupccl/testdata/backup-restore/restore-grants
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ GRANT CREATE ON DATABASE testuser_db TO testuser;
----

exec-sql user=testuser
RESTORE testdb.sc.othertable, testdb.testtable_greeting_usage FROM 'nodelocal://1/test' WITH into_db='testuser_db';
RESTORE testdb.sc.othertable, testdb.testtable_greeting_usage FROM LATEST IN 'nodelocal://1/test' WITH into_db='testuser_db';
----

# Check that user1 doesn't have any privs, but testuser should be the owner.
Expand Down Expand Up @@ -211,7 +211,7 @@ GRANT CREATE ON DATABASE restoredb TO user1;
----

exec-sql
RESTORE testdb.sc.othertable, testdb.testtable_greeting_usage, testdb.testtable_greeting_owner FROM 'nodelocal://1/test' WITH into_db='restoredb';
RESTORE testdb.sc.othertable, testdb.testtable_greeting_usage, testdb.testtable_greeting_owner FROM LATEST IN 'nodelocal://1/test' WITH into_db='restoredb';
----

query-sql
Expand Down Expand Up @@ -268,7 +268,7 @@ DROP DATABASE testdb CASCADE;
----

exec-sql
RESTORE DATABASE testdb FROM 'nodelocal://0/test/';
RESTORE DATABASE testdb FROM LATEST IN 'nodelocal://0/test/';
----


Expand Down Expand Up @@ -350,7 +350,7 @@ DROP DATABASE testdb CASCADE;

# Now, let's restore a single database as a non-admin (testuser).
exec-sql user=testuser
RESTORE DATABASE testdb FROM 'nodelocal://0/test/';
RESTORE DATABASE testdb FROM LATEST IN 'nodelocal://0/test/';
----

# Check that user1 doesn't have any privs.
Expand Down Expand Up @@ -435,7 +435,7 @@ new-server name=s2 share-io-dir=s1 allow-implicit-access
----

exec-sql
RESTORE FROM 'nodelocal://0/test/';
RESTORE FROM LATEST IN 'nodelocal://0/test/';
----

# Check user1.
Expand Down
14 changes: 7 additions & 7 deletions pkg/ccl/backupccl/testdata/backup-restore/restore-permissions
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DROP DATABASE d;
----

exec-sql user=testuser
RESTORE DATABASE d FROM 'nodelocal://0/test/';
RESTORE DATABASE d FROM LATEST IN 'nodelocal://0/test/';
----

# Start a new cluster with the same IO dir.
Expand All @@ -36,12 +36,12 @@ CREATE USER testuser

# Restore into the new cluster.
exec-sql server=s2 user=testuser
RESTORE FROM 'nodelocal://0/test/'
RESTORE FROM LATEST IN 'nodelocal://0/test/'
----
pq: only users with the admin role are allowed to restore full cluster backups

exec-sql server=s2 user=testuser
RESTORE DATABASE d FROM 'nodelocal://0/test/'
RESTORE DATABASE d FROM LATEST IN 'nodelocal://0/test/'
----
pq: only users with the CREATEDB privilege can restore databases

Expand All @@ -50,7 +50,7 @@ CREATE DATABASE d
----

exec-sql server=s2 user=testuser
RESTORE TABLE d.t FROM 'nodelocal://0/test/'
RESTORE TABLE d.t FROM LATEST IN 'nodelocal://0/test/'
----
pq: user testuser does not have CREATE privilege on database d

Expand All @@ -59,7 +59,7 @@ GRANT CREATE ON DATABASE d TO testuser
----

exec-sql server=s2 user=testuser
RESTORE TABLE d.t FROM 'nodelocal://0/test/'
RESTORE TABLE d.t FROM LATEST IN 'nodelocal://0/test/'
----

query-sql server=s2
Expand All @@ -78,7 +78,7 @@ ALTER USER testuser CREATEDB
----

exec-sql server=s2 user=testuser
RESTORE DATABASE d FROM 'nodelocal://0/test/'
RESTORE DATABASE d FROM LATEST IN 'nodelocal://0/test/'
----

query-sql server=s2
Expand All @@ -97,6 +97,6 @@ CREATE USER testuser
----

exec-sql server=s3 user=testuser
RESTORE TABLE d.t FROM 'nodelocal://0/test/'
RESTORE TABLE d.t FROM LATEST IN 'nodelocal://0/test/'
----
pq: only users with the admin role are allowed to RESTORE from the specified nodelocal URI
6 changes: 3 additions & 3 deletions pkg/ccl/backupccl/testdata/backup-restore/row_level_ttl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ WHERE label LIKE 'row-level-ttl-%'
0

exec-sql
RESTORE FROM 'nodelocal://0/full_cluster_backup/'
RESTORE FROM LATEST IN 'nodelocal://0/full_cluster_backup/'
----

query-sql
Expand Down Expand Up @@ -54,7 +54,7 @@ WHERE label LIKE 'row-level-ttl-%'
0

exec-sql
RESTORE DATABASE d FROM 'nodelocal://0/database_backup/'
RESTORE DATABASE d FROM LATEST IN 'nodelocal://0/database_backup/'
----

query-sql
Expand Down Expand Up @@ -87,7 +87,7 @@ CREATE DATABASE d
----

exec-sql
RESTORE TABLE d.public.t FROM 'nodelocal://0/database_backup/'
RESTORE TABLE d.public.t FROM LATEST IN 'nodelocal://0/database_backup/'
----

query-sql
Expand Down
6 changes: 3 additions & 3 deletions pkg/ccl/backupccl/testdata/backup-restore/temp-tables
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ DROP DATABASE d1
----

exec-sql
RESTORE DATABASE d1 FROM 'nodelocal://0/d1_backup/'
RESTORE DATABASE d1 FROM LATEST IN 'nodelocal://0/d1_backup/'
----

exec-sql
Expand Down Expand Up @@ -88,7 +88,7 @@ DROP DATABASE d1
----

exec-sql
RESTORE DATABASE d1 FROM 'nodelocal://0/d1_star_backup/'
RESTORE DATABASE d1 FROM LATEST IN 'nodelocal://0/d1_star_backup/'
----

exec-sql
Expand Down Expand Up @@ -120,7 +120,7 @@ USE defaultdb;
----

exec-sql
RESTORE FROM 'nodelocal://0/full_cluster_backup/';
RESTORE FROM LATEST IN 'nodelocal://0/full_cluster_backup/';
----

# The pg_temp schema from the BACKUP should show up in its original database.
Expand Down
6 changes: 3 additions & 3 deletions pkg/ccl/backupccl/testdata/backup-restore/user-defined-types
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ new-server name=s2 share-io-dir=s1

# Restore into the new cluster.
exec-sql server=s2
RESTORE FROM 'nodelocal://0/test/'
RESTORE FROM LATEST IN 'nodelocal://0/test/'
----

# Check all of the tables have the right data.
Expand Down Expand Up @@ -129,15 +129,15 @@ CREATE TABLE d.expr (

# Backup the database now.
exec-sql
BACKUP DATABASE d INTO LATEST IN 'nodelocal://0/test/'
BACKUP DATABASE d INTO 'nodelocal://0/test/'
----

exec-sql
DROP DATABASE d
----

exec-sql
RESTORE DATABASE d FROM 'nodelocal://0/test/';
RESTORE DATABASE d FROM LATEST IN 'nodelocal://0/test/';
----

# Check the table data.
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/testdata/backup-restore/virtual-columns
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ new-server name=s2 share-io-dir=s1
----

exec-sql server=s2
RESTORE FROM 'nodelocal://0/test/'
RESTORE FROM LATEST IN 'nodelocal://0/test/'
----

query-sql
Expand Down

0 comments on commit 45288c7

Please sign in to comment.