001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.backup;
019
020import static org.junit.Assert.assertEquals;
021import static org.junit.Assert.assertTrue;
022
023import java.util.HashSet;
024import java.util.List;
025import org.apache.hadoop.fs.Path;
026import org.apache.hadoop.hbase.HBaseClassTestRule;
027import org.apache.hadoop.hbase.backup.impl.BackupManifest;
028import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
029import org.apache.hadoop.hbase.testclassification.LargeTests;
030import org.apache.hadoop.util.ToolRunner;
031import org.junit.ClassRule;
032import org.junit.Test;
033import org.junit.experimental.categories.Category;
034import org.slf4j.Logger;
035import org.slf4j.LoggerFactory;
036
037import org.apache.hbase.thirdparty.com.google.common.collect.Sets;
038
039@Category(LargeTests.class)
040public class TestFullBackup extends TestBackupBase {
041
042  @ClassRule
043  public static final HBaseClassTestRule CLASS_RULE =
044    HBaseClassTestRule.forClass(TestFullBackup.class);
045
046  private static final Logger LOG = LoggerFactory.getLogger(TestFullBackup.class);
047
048  @Test
049  public void testFullBackupMultipleCommand() throws Exception {
050    LOG.info("test full backup on a multiple tables with data: command-line");
051    try (BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {
052      int before = table.getBackupHistory().size();
053      String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-t",
054        table1.getNameAsString() + "," + table2.getNameAsString() };
055      // Run backup
056      int ret = ToolRunner.run(conf1, new BackupDriver(), args);
057      assertTrue(ret == 0);
058      List<BackupInfo> backups = table.getBackupHistory();
059      int after = table.getBackupHistory().size();
060      assertTrue(after == before + 1);
061      for (BackupInfo data : backups) {
062        String backupId = data.getBackupId();
063        assertTrue(checkSucceeded(backupId));
064      }
065
066      BackupInfo newestBackup = backups.get(0);
067      BackupManifest manifest =
068        HBackupFileSystem.getManifest(conf1, new Path(BACKUP_ROOT_DIR), newestBackup.getBackupId());
069      assertEquals(Sets.newHashSet(table1, table2), new HashSet<>(manifest.getTableList()));
070    }
071    LOG.info("backup complete");
072  }
073
074}