diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/ClientSnapshotDescriptionUtils.java hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/ClientSnapshotDescriptionUtils.java index 59ba837..4bcfa4e 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/ClientSnapshotDescriptionUtils.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/ClientSnapshotDescriptionUtils.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.snapshot; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.backup.impl.BackupSystemTable; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos; import org.apache.hadoop.hbase.util.Bytes; @@ -44,7 +45,8 @@ public class ClientSnapshotDescriptionUtils { // make sure the table name is valid, this will implicitly check validity TableName tableName = TableName.valueOf(snapshot.getTable()); - if (tableName.isSystemTable()) { + if (tableName.isSystemTable() && !BackupSystemTable.getTableName().equals(tableName)) { + // allow hbase:backup table snapshot throw new IllegalArgumentException("System table snapshots are not allowed"); } } diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestSystemTableBackup.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestSystemTableBackup.java new file mode 100644 index 0000000..7498cba --- /dev/null +++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestSystemTableBackup.java @@ -0,0 +1,70 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable + * law or agreed to in writing, software distributed under the License is distributed on an "AS IS" + * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License + * for the specific language governing permissions and limitations under the License. + */ + +package org.apache.hadoop.hbase.backup; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.backup.impl.BackupSystemTable; +import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import com.google.common.collect.Lists; + +@Category(LargeTests.class) +public class TestSystemTableBackup extends TestBackupBase { + + private static final Log LOG = LogFactory.getLog(TestSystemTableBackup.class); + + /** + * Verify that a single table is restored to a new table + * @throws Exception + */ + @Test + public void testBackupRestoreSystemTable() throws Exception { + + LOG.info("test full restore on a single table empty table"); + + List tables = Lists.newArrayList(table1); + String backupId = fullTableBackup(tables); + assertTrue(checkSucceeded(backupId)); + + LOG.info("backup complete"); + TableName backupSystem = BackupSystemTable.getTableName(); + + int rowCount = TEST_UTIL.countRows(backupSystem); + + HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); + String snapshotName = "sysTable"; + hba.snapshot(snapshotName, backupSystem); + // Backup one more time + backupId = fullTableBackup(tables); + assertTrue(checkSucceeded(backupId)); + int rowCountAfterBackup = TEST_UTIL.countRows(backupSystem); + assertTrue(rowCountAfterBackup > rowCount); + hba.disableTable(backupSystem); + hba.restoreSnapshot(snapshotName); + hba.enableTable(backupSystem); + int count = TEST_UTIL.countRows(backupSystem); + assertEquals(rowCount, count); + hba.close(); + } + + +} \ No newline at end of file