@@ -17,6 +17,7 @@ import (
1717 "sync/atomic"
1818 "testing"
1919
20+ "github.com/cockroachdb/cockroach/pkg/backup/backuptestutils"
2021 "github.com/cockroachdb/cockroach/pkg/base"
2122 "github.com/cockroachdb/cockroach/pkg/cloud/nodelocal"
2223 "github.com/cockroachdb/cockroach/pkg/jobs"
@@ -73,7 +74,7 @@ func TestOnlineRestoreBasic(t *testing.T) {
7374 rtc , rSQLDB , cleanupFnRestored := backupRestoreTestSetupEmpty (t , 1 , dir , InitManualReplication , orParams )
7475 defer cleanupFnRestored ()
7576
76- externalStorage := "nodelocal://1/backup"
77+ externalStorage := backuptestutils . GetExternalStorageURI ( t , "nodelocal://1/backup" , "backup" , sqlDB , rSQLDB )
7778
7879 createStmt := `SELECT create_statement FROM [SHOW CREATE TABLE data.bank]`
7980 createStmtRes := sqlDB .QueryStr (t , createStmt )
@@ -124,11 +125,12 @@ func TestOnlineRestoreRecovery(t *testing.T) {
124125
125126 const numAccounts = 1000
126127
127- externalStorage := "nodelocal://1/backup"
128-
129128 _ , sqlDB , _ , cleanupFn := backupRestoreTestSetupWithParams (t , singleNode , numAccounts , InitManualReplication , orParams )
130129 defer cleanupFn ()
131130
131+ trueExternalStorage := "nodelocal://1/backup"
132+ externalStorage := backuptestutils .GetExternalStorageURI (t , trueExternalStorage , "backup" , sqlDB )
133+
132134 restoreToPausedDownloadJob := func (t * testing.T , newDBName string ) int {
133135 defer func () {
134136 sqlDB .Exec (t , "SET CLUSTER SETTING jobs.debug.pausepoints = ''" )
@@ -169,7 +171,7 @@ func TestOnlineRestoreRecovery(t *testing.T) {
169171 t .Run ("delete file" , func (t * testing.T ) {
170172 dbName := "data_delete"
171173 downloadJobID := restoreToPausedDownloadJob (t , dbName )
172- corruptBackup (t , sqlDB , tmpDir , externalStorage )
174+ corruptBackup (t , sqlDB , tmpDir , trueExternalStorage )
173175 sqlDB .ExpectErr (t , "no such file or directory" , "SELECT count(*) FROM data_delete.bank" )
174176 sqlDB .Exec (t , fmt .Sprintf ("RESUME JOB %d" , downloadJobID ))
175177 jobutils .WaitForJobToFail (t , sqlDB , jobspb .JobID (downloadJobID ))
@@ -200,7 +202,7 @@ func TestOnlineRestoreRecovery(t *testing.T) {
200202 var blockingJobID int
201203 sqlDB .QueryRow (t , fmt .Sprintf ("RESTORE DATABASE data FROM LATEST IN '%s' WITH EXPERIMENTAL COPY, new_db_name=%s, detached" , externalStorage , dbName )).Scan (& blockingJobID )
202204 jobutils .WaitForJobToPause (t , sqlDB , jobspb .JobID (blockingJobID ))
203- corruptBackup (t , sqlDB , tmpDir , externalStorage )
205+ corruptBackup (t , sqlDB , tmpDir , trueExternalStorage )
204206 sqlDB .Exec (t , "SET CLUSTER SETTING jobs.debug.pausepoints = ''" )
205207 sqlDB .Exec (t , fmt .Sprintf ("RESUME JOB %d" , blockingJobID ))
206208 jobutils .WaitForJobToFail (t , sqlDB , jobspb .JobID (blockingJobID ))
@@ -220,11 +222,12 @@ func TestFullClusterOnlineRestoreRecovery(t *testing.T) {
220222
221223 const numAccounts = 1000
222224
223- externalStorage := "nodelocal://1/backup"
224-
225225 _ , sqlDB , _ , cleanupFn := backupRestoreTestSetupWithParams (t , singleNode , numAccounts , InitManualReplication , orParams )
226226 defer cleanupFn ()
227227
228+ trueExternalStorage := "nodelocal://1/backup"
229+ externalStorage := backuptestutils .GetExternalStorageURI (t , trueExternalStorage , "backup" , sqlDB )
230+
228231 sqlDB .Exec (t , "SET CLUSTER SETTING jobs.debug.pausepoints = 'restore.before_download'" )
229232 sqlDB .Exec (t , fmt .Sprintf ("BACKUP INTO '%s'" , externalStorage ))
230233
@@ -248,7 +251,7 @@ func TestFullClusterOnlineRestoreRecovery(t *testing.T) {
248251 var downloadJobID jobspb.JobID
249252 sqlDB .QueryRow (t , latestDownloadJobIDQuery ).Scan (& downloadJobID )
250253 jobutils .WaitForJobToPause (t , sqlDB , downloadJobID )
251- corruptBackup (t , sqlDB , tmpDir , externalStorage )
254+ corruptBackup (t , sqlDB , tmpDir , trueExternalStorage )
252255 sqlDB .Exec (t , "SET CLUSTER SETTING jobs.debug.pausepoints = ''" )
253256 sqlDB .Exec (t , fmt .Sprintf ("RESUME JOB %d" , downloadJobID ))
254257 jobutils .WaitForJobToFail (t , sqlDB , downloadJobID )
@@ -292,13 +295,17 @@ func TestOnlineRestorePartitioned(t *testing.T) {
292295 )
293296 defer cleanupFn ()
294297
295- sqlDB . Exec (t , `BACKUP DATABASE data INTO (' nodelocal://1/a?COCKROACH_LOCALITY=default',
296- ' nodelocal://1/b?COCKROACH_LOCALITY=dc%3Ddc2',
297- ' nodelocal://1/c?COCKROACH_LOCALITY=dc%3Ddc3')` )
298+ a := backuptestutils . GetExternalStorageURI (t , " nodelocal://1/a" , "conn-a" , sqlDB ) + " ?COCKROACH_LOCALITY=default"
299+ b := backuptestutils . GetExternalStorageURI ( t , " nodelocal://1/b" , "conn-b" , sqlDB ) + " ?COCKROACH_LOCALITY=dc%3Ddc2"
300+ c := backuptestutils . GetExternalStorageURI ( t , " nodelocal://1/c" , "conn-c" , sqlDB ) + " ?COCKROACH_LOCALITY=dc%3Ddc3"
298301
299- j := sqlDB .QueryStr (t , `RESTORE DATABASE data FROM LATEST IN ('nodelocal://1/a?COCKROACH_LOCALITY=default',
300- 'nodelocal://1/b?COCKROACH_LOCALITY=dc%3Ddc2',
301- 'nodelocal://1/c?COCKROACH_LOCALITY=dc%3Ddc3') WITH new_db_name='d2', EXPERIMENTAL DEFERRED COPY` )
302+ sqlDB .Exec (t , fmt .Sprintf ("BACKUP DATABASE data INTO ('%s', '%s', '%s')" , a , b , c ))
303+
304+ j := sqlDB .QueryStr (t , fmt .Sprintf (
305+ `RESTORE DATABASE data FROM LATEST IN ('%s', '%s', '%s')
306+ WITH new_db_name='d2', EXPERIMENTAL DEFERRED COPY` ,
307+ a , b , c ,
308+ ))
302309
303310 srv .Servers [0 ].JobRegistry ().(* jobs.Registry ).TestingNudgeAdoptionQueue ()
304311
@@ -321,11 +328,14 @@ func TestOnlineRestoreLinkCheckpoint(t *testing.T) {
321328 orParams ,
322329 )
323330 defer cleanupFn ()
324- sqlDB .Exec (t , "BACKUP DATABASE data INTO $1" , localFoo )
331+
332+ externalStorage := backuptestutils .GetExternalStorageURI (t , "nodelocal://1/backup" , "backup" , sqlDB )
333+
334+ sqlDB .Exec (t , "BACKUP DATABASE data INTO $1" , externalStorage )
325335 sqlDB .Exec (t , "SET CLUSTER SETTING jobs.debug.pausepoints = 'restore.before_publishing_descriptors'" )
326336 var jobID jobspb.JobID
327337 stmt := fmt .Sprintf ("RESTORE DATABASE data FROM LATEST IN $1 WITH OPTIONS (new_db_name='data2', %s, detached)" , onlineImpl (rng ))
328- sqlDB .QueryRow (t , stmt , localFoo ).Scan (& jobID )
338+ sqlDB .QueryRow (t , stmt , externalStorage ).Scan (& jobID )
329339 jobutils .WaitForJobToPause (t , sqlDB , jobID )
330340
331341 // Set a pauspoint during the link phase which should not get hit because of
@@ -354,18 +364,20 @@ func TestOnlineRestoreStatementResult(t *testing.T) {
354364 )
355365 defer cleanupFn ()
356366
367+ externalStorage := backuptestutils .GetExternalStorageURI (t , "nodelocal://1/backup" , "backup" , sqlDB )
368+
357369 sqlDB .ExecMultiple (
358370 t ,
359371 "USE data" ,
360372 "CREATE TABLE foo (x INT PRIMARY KEY, y INT)" ,
361373 "INSERT INTO foo VALUES (1, 2)" ,
362374 )
363- sqlDB .Exec (t , "BACKUP DATABASE data INTO $1" , localFoo )
375+ sqlDB .Exec (t , "BACKUP DATABASE data INTO $1" , externalStorage )
364376
365377 rows := sqlDB .Query (
366378 t ,
367379 "RESTORE DATABASE data FROM LATEST IN $1 WITH OPTIONS (new_db_name='data2', experimental deferred copy)" ,
368- localFoo ,
380+ externalStorage ,
369381 )
370382 columns , err := rows .Columns ()
371383 if err != nil {
@@ -419,7 +431,7 @@ func TestOnlineRestoreWaitForDownload(t *testing.T) {
419431 },
420432 })
421433 defer cleanupFn ()
422- externalStorage := "nodelocal://1/backup"
434+ externalStorage := backuptestutils . GetExternalStorageURI ( t , "nodelocal://1/backup" , "backup" , sqlDB )
423435
424436 sqlDB .Exec (t , fmt .Sprintf ("BACKUP INTO '%s'" , externalStorage ))
425437
@@ -445,8 +457,6 @@ func TestOnlineRestoreTenant(t *testing.T) {
445457
446458 defer nodelocal .ReplaceNodeLocalForTesting (t .TempDir ())()
447459
448- externalStorage := "nodelocal://1/backup"
449-
450460 params := base.TestClusterArgs {ServerArgs : base.TestServerArgs {
451461 Knobs : base.TestingKnobs {
452462 JobsTestingKnobs : jobs .NewTestingKnobsWithShortIntervals (),
@@ -467,6 +477,8 @@ func TestOnlineRestoreTenant(t *testing.T) {
467477 defer cleanupFn ()
468478 srv := tc .Server (0 )
469479
480+ externalStorage := backuptestutils .GetExternalStorageURI (t , "nodelocal://1/backup" , "backup" , systemDB )
481+
470482 _ = securitytest .EmbeddedTenantIDs ()
471483
472484 _ , conn10 := serverutils .StartTenant (t , srv , base.TestTenantArgs {TenantID : roachpb .MustMakeTenantID (10 )})
@@ -479,6 +491,9 @@ func TestOnlineRestoreTenant(t *testing.T) {
479491 restoreTC , rSQLDB , cleanupFnRestored := backupRestoreTestSetupEmpty (t , 1 , dir , InitManualReplication , params )
480492 defer cleanupFnRestored ()
481493
494+ // just using this to run CREATE EXTERNAL CONNECTION on the recovery db if we're using one
495+ _ = backuptestutils .GetExternalStorageURI (t , "nodelocal://1/backup" , "backup" , rSQLDB )
496+
482497 systemDB .Exec (t , fmt .Sprintf (`BACKUP TENANT 10 INTO '%s'` , externalStorage ))
483498
484499 if incremental {
@@ -555,9 +570,15 @@ func TestOnlineRestoreErrors(t *testing.T) {
555570 defer cleanupFnRestored ()
556571 rSQLDB .Exec (t , "CREATE DATABASE data" )
557572 var (
558- fullBackup = "nodelocal://1/full-backup"
559- fullBackupWithRevs = "nodelocal://1/full-backup-with-revs"
560- incrementalBackupWithRevs = "nodelocal://1/incremental-backup-with-revs"
573+ fullBackup = backuptestutils .GetExternalStorageURI (
574+ t , "nodelocal://1/full-backup" , "full-backup" , sqlDB , rSQLDB ,
575+ )
576+ fullBackupWithRevs = backuptestutils .GetExternalStorageURI (
577+ t , "nodelocal://1/full-backup-with-revs" , "full-backup-with-revs" , sqlDB , rSQLDB ,
578+ )
579+ incrementalBackupWithRevs = backuptestutils .GetExternalStorageURI (
580+ t , "nodelocal://1/incremental-backup-with-revs" , "incremental-backup-with-revs" , sqlDB , rSQLDB ,
581+ )
561582 )
562583 t .Run ("full backups with revision history are unsupported" , func (t * testing.T ) {
563584 var systemTime string
@@ -625,7 +646,7 @@ func TestOnlineRestoreRetryingDownloadRequests(t *testing.T) {
625646 )
626647 defer cleanupFn ()
627648
628- externalStorage := "nodelocal://1/backup"
649+ externalStorage := backuptestutils . GetExternalStorageURI ( t , "nodelocal://1/backup" , "backup" , sqlDB )
629650 sqlDB .Exec (t , fmt .Sprintf ("BACKUP INTO '%s'" , externalStorage ))
630651 sqlDB .Exec (
631652 t ,
@@ -684,7 +705,7 @@ func TestOnlineRestoreDownloadRetryReset(t *testing.T) {
684705 )
685706 defer cleanupFn ()
686707
687- externalStorage := "nodelocal://1/backup"
708+ externalStorage := backuptestutils . GetExternalStorageURI ( t , "nodelocal://1/backup" , "backup" , sqlDB )
688709 sqlDB .Exec (t , fmt .Sprintf ("BACKUP INTO '%s'" , externalStorage ))
689710 sqlDB .Exec (
690711 t ,
@@ -769,7 +790,7 @@ func TestOnlineRestoreFailScatterNonEmptyRanges(t *testing.T) {
769790 )
770791 defer cleanupFn ()
771792
772- externalStorage := "nodelocal://1/backup"
793+ externalStorage := backuptestutils . GetExternalStorageURI ( t , "nodelocal://1/backup" , "backup" , sqlDB )
773794 sqlDB .Exec (t , fmt .Sprintf ("BACKUP INTO '%s'" , externalStorage ))
774795
775796 var linkJobID jobspb.JobID
0 commit comments