@@ -95,7 +95,7 @@ public void testContinuousBackupWithFullBackup() throws Exception {
9595 int before = table .getBackupHistory ().size ();
9696
9797 // Run backup
98- String [] args = buildBackupArgs ("full" , new TableName [] { tableName });
98+ String [] args = buildBackupArgs ("full" , new TableName [] { tableName }, true );
9999 int ret = ToolRunner .run (conf1 , new BackupDriver (), args );
100100 assertEquals ("Backup should succeed" , 0 , ret );
101101
@@ -133,12 +133,12 @@ public void testContinuousBackupForMultipleTables() throws Exception {
133133 int before = table .getBackupHistory ().size ();
134134
135135 // Create full backup for table1
136- String [] args = buildBackupArgs ("full" , new TableName [] { tableName1 });
136+ String [] args = buildBackupArgs ("full" , new TableName [] { tableName1 }, true );
137137 int ret = ToolRunner .run (conf1 , new BackupDriver (), args );
138138 assertEquals ("Backup should succeed" , 0 , ret );
139139
140140 // Create full backup for table2
141- args = buildBackupArgs ("full" , new TableName [] { tableName2 });
141+ args = buildBackupArgs ("full" , new TableName [] { tableName2 }, true );
142142 ret = ToolRunner .run (conf1 , new BackupDriver (), args );
143143 assertEquals ("Backup should succeed" , 0 , ret );
144144
@@ -165,6 +165,39 @@ public void testContinuousBackupForMultipleTables() throws Exception {
165165 verifyTableInBackupSystemTable (tableName2 );
166166 }
167167
168+ @ Test
169+ public void testInvalidBackupScenarioWithContinuousEnabled () throws Exception {
170+ LOG .info ("Testing invalid backup scenario with continuous backup enabled" );
171+ String methodName = Thread .currentThread ().getStackTrace ()[1 ].getMethodName ();
172+ TableName tableName1 = TableName .valueOf ("table_" + methodName );
173+ TEST_UTIL .createTable (tableName1 , "cf" );
174+ TableName tableName2 = TableName .valueOf ("table_" + methodName + "2" );
175+ TEST_UTIL .createTable (tableName2 , "cf" );
176+
177+ try (BackupSystemTable table = new BackupSystemTable (TEST_UTIL .getConnection ())) {
178+ int before = table .getBackupHistory ().size ();
179+
180+ // Create full backup for table1 with continuous backup enabled
181+ String [] args = buildBackupArgs ("full" , new TableName [] { tableName1 }, true );
182+ int ret = ToolRunner .run (conf1 , new BackupDriver (), args );
183+ assertEquals ("Backup should succeed" , 0 , ret );
184+
185+ // Create full backup for table2 without continuous backup enabled
186+ args = buildBackupArgs ("full" , new TableName [] { tableName2 }, false );
187+ ret = ToolRunner .run (conf1 , new BackupDriver (), args );
188+ assertEquals ("Backup should succeed" , 0 , ret );
189+
190+ // Attempt full backup for both tables without continuous backup enabled (should fail)
191+ args = buildBackupArgs ("full" , new TableName [] { tableName1 , tableName2 }, false );
192+ ret = ToolRunner .run (conf1 , new BackupDriver (), args );
193+ assertTrue ("Backup should fail due to mismatch in continuous backup settings" , ret != 0 );
194+
195+ // Verify backup history size is unchanged after the failed backup
196+ int after = table .getBackupHistory ().size ();
197+ assertEquals ("Backup history should remain unchanged on failure" , before + 2 , after );
198+ }
199+ }
200+
168201 @ Test
169202 public void testContinuousBackupWithWALDirNotSpecified () throws Exception {
170203 LOG .info ("Testing that continuous backup fails when WAL directory is not specified" );
@@ -179,7 +212,7 @@ public void testContinuousBackupWithWALDirNotSpecified() throws Exception {
179212 int before = table .getBackupHistory ().size ();
180213
181214 // Run full backup without specifying WAL directory (invalid scenario)
182- String [] args = buildBackupArgs ("full" , new TableName [] { tableName });
215+ String [] args = buildBackupArgs ("full" , new TableName [] { tableName }, true );
183216 int ret = ToolRunner .run (conf1 , new BackupDriver (), args );
184217
185218 assertTrue ("Backup should fail when WAL directory is not specified" , ret != 0 );
@@ -204,7 +237,7 @@ public void testContinuousBackupWithIncrementalBackup() throws Exception {
204237 int before = table .getBackupHistory ().size ();
205238
206239 // Run incremental backup with continuous backup flag (invalid scenario)
207- String [] args = buildBackupArgs ("incremental" , new TableName [] { tableName });
240+ String [] args = buildBackupArgs ("incremental" , new TableName [] { tableName }, true );
208241 int ret = ToolRunner .run (conf1 , new BackupDriver (), args );
209242
210243 assertTrue ("Backup should fail when using continuous backup with incremental mode" , ret != 0 );
@@ -226,12 +259,17 @@ private void verifyReplicationPeerSubscription(TableName table) throws IOExcepti
226259 }
227260 }
228261
229- private String [] buildBackupArgs (String backupType , TableName [] tables ) {
262+ private String [] buildBackupArgs (String backupType , TableName [] tables ,
263+ boolean continuousEnabled ) {
230264 String tableNames =
231265 Arrays .stream (tables ).map (TableName ::getNameAsString ).collect (Collectors .joining ("," ));
232266
233- return new String [] { "create" , backupType , BACKUP_ROOT_DIR , "-t" , tableNames ,
234- "-" + OPTION_ENABLE_CONTINUOUS_BACKUP };
267+ if (continuousEnabled ) {
268+ return new String [] { "create" , backupType , BACKUP_ROOT_DIR , "-t" , tableNames ,
269+ "-" + OPTION_ENABLE_CONTINUOUS_BACKUP };
270+ } else {
271+ return new String [] { "create" , backupType , BACKUP_ROOT_DIR , "-t" , tableNames };
272+ }
235273 }
236274
237275 private BackupManifest getLatestBackupManifest (List <BackupInfo > backups ) throws IOException {
0 commit comments