@@ -2037,6 +2037,7 @@ func TestCheckSystemPartsColumns(t *testing.T) {
20372037 env .Cleanup (t , r )
20382038}
20392039
2040+ // // https://github.com/Altinity/clickhouse-backup/issues/871
20402041func TestKeepBackupRemoteAndDiffFromRemote (t * testing.T ) {
20412042 if isTestShouldSkip ("RUN_ADVANCED_TESTS" ) {
20422043 t .Skip ("Skipping Advanced integration tests..." )
@@ -2056,27 +2057,37 @@ func TestKeepBackupRemoteAndDiffFromRemote(t *testing.T) {
20562057 for backupNumber , backupName := range backupNames {
20572058 if backupNumber == 0 {
20582059 env .DockerExecNoError (r , "clickhouse-backup" , "bash" , "-ce" , fmt .Sprintf ("BACKUPS_TO_KEEP_REMOTE=3 CLICKHOUSE_BACKUP_CONFIG=/etc/clickhouse-backup/config-s3.yml clickhouse-backup create_remote %s" , backupName ))
2060+ } else if backupNumber == 3 {
2061+ env .DockerExecNoError (r , "clickhouse-backup" , "bash" , "-ce" , fmt .Sprintf ("BACKUPS_TO_KEEP_REMOTE=3 CLICKHOUSE_BACKUP_CONFIG=/etc/clickhouse-backup/config-s3.yml clickhouse-backup create_remote --diff-from-remote=%s %s" , backupNames [backupNumber - 1 ], backupName ))
20592062 } else {
20602063 incrementData = generateIncrementTestData (t , r , env , "S3" , false , incrementData , backupNumber )
20612064 env .DockerExecNoError (r , "clickhouse-backup" , "bash" , "-ce" , fmt .Sprintf ("BACKUPS_TO_KEEP_REMOTE=3 CLICKHOUSE_BACKUP_CONFIG=/etc/clickhouse-backup/config-s3.yml clickhouse-backup create_remote --diff-from-remote=%s %s" , backupNames [backupNumber - 1 ], backupName ))
20622065 }
20632066 }
20642067 out , err := env .DockerExecOut ("clickhouse-backup" , "bash" , "-ce" , "clickhouse-backup -c /etc/clickhouse-backup/config-s3.yml list local" )
20652068 r .NoError (err , "%s\n unexpected list local error: %v" , out , err )
2066- // shall not delete any backup, cause all deleted backups have links as required in other backups
20672069 for _ , backupName := range backupNames {
20682070 r .Contains (out , backupName )
20692071 env .DockerExecNoError (r , "clickhouse-backup" , "clickhouse-backup" , "-c" , "/etc/clickhouse-backup/config-s3.yml" , "delete" , "local" , backupName )
20702072 }
2073+ out , err = env .DockerExecOut ("clickhouse-backup" , "bash" , "-ce" , "clickhouse-backup -c /etc/clickhouse-backup/config-s3.yml list remote" )
2074+ r .NoError (err , "%s\n unexpected list remote error: %v" , out , err )
2075+ // shall not delete any backup on remote, cause all deleted backups have links as required in other backups
2076+ for _ , backupName := range backupNames {
2077+ r .Regexp ("(?m)^" + backupName , out )
2078+ }
2079+
20712080 latestIncrementBackup := fmt .Sprintf ("keep_remote_backup_%d" , len (backupNames )- 1 )
20722081 env .DockerExecNoError (r , "clickhouse-backup" , "clickhouse-backup" , "-c" , "/etc/clickhouse-backup/config-s3.yml" , "download" , latestIncrementBackup )
20732082 out , err = env .DockerExecOut ("clickhouse-backup" , "bash" , "-ce" , "clickhouse-backup -c /etc/clickhouse-backup/config-s3.yml list local" )
20742083 r .NoError (err , "%s\n unexpected list local error: %v" , out , err )
20752084 prevIncrementBackup := fmt .Sprintf ("keep_remote_backup_%d" , len (backupNames )- 2 )
20762085 for _ , backupName := range backupNames {
20772086 if backupName == latestIncrementBackup {
2078- r .Contains (out , backupName )
2087+ r .Regexp ("(?m)^" + backupName , out )
2088+ r .NotContains (out , "+" + backupName )
20792089 } else if backupName == prevIncrementBackup {
2090+ r .NotRegexp ("(?m)^" + backupName , out )
20802091 r .Contains (out , "+" + backupName )
20812092 } else {
20822093 r .NotContains (out , backupName )
@@ -2085,7 +2096,8 @@ func TestKeepBackupRemoteAndDiffFromRemote(t *testing.T) {
20852096 env .DockerExecNoError (r , "clickhouse-backup" , "clickhouse-backup" , "-c" , "/etc/clickhouse-backup/config-s3.yml" , "restore" , "--rm" , latestIncrementBackup )
20862097 var res uint64
20872098 r .NoError (env .ch .SelectSingleRowNoCtx (& res , fmt .Sprintf ("SELECT count() FROM `%s_%s`.`%s_%s`" , Issue331Issue1091Atomic , t .Name (), Issue331Issue1091Atomic , t .Name ())))
2088- r .Equal (uint64 (100 + 20 * 4 ), res )
2099+ numBackupsWithData := 3
2100+ r .Equal (uint64 (100 + 20 * numBackupsWithData ), res )
20892101 fullCleanup (t , r , env , []string {latestIncrementBackup }, []string {"local" }, nil , true , true , "config-s3.yml" )
20902102 fullCleanup (t , r , env , backupNames , []string {"remote" }, databaseList , true , true , "config-s3.yml" )
20912103 env .checkObjectStorageIsEmpty (t , r , "S3" )
@@ -2626,7 +2638,6 @@ func (env *TestEnvironment) runMainIntegrationScenario(t *testing.T, remoteStora
26262638 // main test scenario
26272639 fullBackupName := fmt .Sprintf ("%s_full_%d" , t .Name (), rand .Int ())
26282640 incrementBackupName := fmt .Sprintf ("%s_increment_%d" , t .Name (), rand .Int ())
2629- incrementBackupNameEmpty := fmt .Sprintf ("%s_incrementEmpty_%d" , t .Name (), rand .Int ())
26302641 incrementBackupName2 := fmt .Sprintf ("%s_increment2_%d" , t .Name (), rand .Int ())
26312642 databaseList := []string {dbNameOrdinary , dbNameAtomic , dbNameMySQL , dbNamePostgreSQL , Issue331Issue1091Atomic , Issue331Issue1091Ordinary }
26322643 tablesPattern := fmt .Sprintf ("*_%s.*" , t .Name ())
@@ -2643,37 +2654,6 @@ func (env *TestEnvironment) runMainIntegrationScenario(t *testing.T, remoteStora
26432654 uploadCmd := fmt .Sprintf ("%s_COMPRESSION_FORMAT=zstd CLICKHOUSE_BACKUP_CONFIG=/etc/clickhouse-backup/%s clickhouse-backup upload --resume %s" , remoteStorageType , backupConfig , fullBackupName )
26442655 env .checkResumeAlreadyProcessed (uploadCmd , fullBackupName , "upload" , r , remoteStorageType )
26452656
2646- // https://github.com/Altinity/clickhouse-backup/issues/871
2647- if ! strings .Contains (remoteStorageType , "CUSTOM" ) {
2648- log .Debug ().Msg ("Create+upload incrementEmpty without data" )
2649- env .DockerExecNoError (r , "clickhouse-backup" , "clickhouse-backup" , "-c" , "/etc/clickhouse-backup/" + backupConfig , "create" , "--tables" , tablesPattern , "--diff-from-remote" , fullBackupName , incrementBackupNameEmpty )
2650- out , err = env .DockerExecOut ("clickhouse-backup" , "bash" , "-ec" , "clickhouse-backup -c /etc/clickhouse-backup/" + backupConfig + " list local | grep " + incrementBackupNameEmpty )
2651- r .NoError (err , out )
2652- r .Contains (out , "+" + fullBackupName )
2653- r .Contains (out , incrementBackupNameEmpty )
2654- if ! strings .Contains (remoteStorageType , "EMBEDDED" ) {
2655- r .Contains (out , "data:0B" )
2656- } else {
2657- r .Contains (out , "arch:0B" )
2658- }
2659- env .DockerExecNoError (r , "clickhouse-backup" , "clickhouse-backup" , "-c" , "/etc/clickhouse-backup/" + backupConfig , "upload" , "--env" , "BACKUPS_TO_KEEP_REMOTE=2" , "--env" , "ALLOW_EMPTY_BACKUPS=1" , "--diff-from-remote" , fullBackupName , incrementBackupNameEmpty )
2660- out , err = env .DockerExecOut ("clickhouse-backup" , "bash" , "-ec" , "clickhouse-backup -c /etc/clickhouse-backup/" + backupConfig + " list remote | grep '^" + fullBackupName + "'" )
2661- r .NoError (err , out )
2662- r .Contains (out , fullBackupName )
2663- r .NotContains (out , "data:0B" )
2664- out , err = env .DockerExecOut ("clickhouse-backup" , "bash" , "-ec" , "clickhouse-backup -c /etc/clickhouse-backup/" + backupConfig + " list remote | grep " + incrementBackupNameEmpty )
2665- r .NoError (err , out )
2666- r .Contains (out , "+" + fullBackupName )
2667- r .Contains (out , incrementBackupNameEmpty )
2668- if ! strings .Contains (remoteStorageType , "EMBEDDED" ) {
2669- r .Contains (out , "data:0B" )
2670- } else {
2671- r .Contains (out , "arch:0B" )
2672- }
2673- env .DockerExecNoError (r , "clickhouse-backup" , "clickhouse-backup" , "-c" , "/etc/clickhouse-backup/" + backupConfig , "delete" , "remote" , incrementBackupNameEmpty )
2674- env .DockerExecNoError (r , "clickhouse-backup" , "clickhouse-backup" , "-c" , "/etc/clickhouse-backup/" + backupConfig , "delete" , "local" , incrementBackupNameEmpty )
2675- }
2676-
26772657 log .Debug ().Msg ("Create increment1 with data" )
26782658 incrementData := generateIncrementTestData (t , r , env , remoteStorageType , createAllTypesOfObjectTables , defaultIncrementData , 1 )
26792659 env .DockerExecNoError (r , "clickhouse-backup" , "clickhouse-backup" , "-c" , "/etc/clickhouse-backup/" + backupConfig , "create" , "--tables" , tablesPattern , incrementBackupName )
@@ -3084,8 +3064,9 @@ func (env *TestEnvironment) checkResumeAlreadyProcessed(backupCmd, testBackupNam
30843064 r .NotContains (out , resumableWarning )
30853065 r .NotContains (out , resumableCleanup )
30863066 r .Contains (out , alreadyProcesses )
3067+ } else {
3068+ log .Debug ().Msg (out )
30873069 }
3088- log .Debug ().Msg (out )
30893070}
30903071
30913072func fullCleanup (t * testing.T , r * require.Assertions , env * TestEnvironment , backupNames , backupTypes , databaseList []string , checkDeleteErr , checkDeleteOtherErr bool , backupConfig string ) {
0 commit comments