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 java.net.URI; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.fs.Path; 023import org.apache.hadoop.hbase.HBaseConfiguration; 024import org.apache.hadoop.hbase.TableName; 025import org.apache.hadoop.hbase.backup.impl.BackupAdminImpl; 026import org.apache.hadoop.hbase.backup.util.BackupUtils; 027import org.apache.hadoop.hbase.client.Connection; 028import org.apache.hadoop.hbase.client.ConnectionFactory; 029import org.apache.hadoop.hbase.util.CommonFSUtils; 030import org.apache.hadoop.util.ToolRunner; 031import org.apache.yetus.audience.InterfaceAudience; 032 033/** 034 * Command-line entry point for restore operation 035 */ 036@InterfaceAudience.Private 037public class RestoreDriver extends AbstractRestoreDriver { 038 private static final String USAGE_STRING = """ 039 Usage: hbase restore <backup_path> <backup_id> [options] 040 backup_path Path to a backup destination root 041 backup_id Backup image ID to restore 042 table(s) Comma-separated list of tables to restore 043 """; 044 045 @Override 046 protected int executeRestore(boolean check, TableName[] fromTables, TableName[] toTables, 047 boolean isOverwrite) { 048 // parse main restore command options 049 String[] remainArgs = cmd.getArgs(); 050 if (remainArgs.length != 2) { 051 printToolUsage(); 052 return -1; 053 } 054 055 String backupRootDir = remainArgs[0]; 056 String backupId = remainArgs[1]; 057 058 try (final Connection conn = ConnectionFactory.createConnection(conf); 059 BackupAdmin client = new BackupAdminImpl(conn)) { 060 client.restore(BackupUtils.createRestoreRequest(backupRootDir, backupId, check, fromTables, 061 toTables, isOverwrite)); 062 } catch (Exception e) { 063 LOG.error("Error while running restore backup", e); 064 return -5; 065 } 066 return 0; 067 } 068 069 public static void main(String[] args) throws Exception { 070 Configuration conf = HBaseConfiguration.create(); 071 Path hbasedir = CommonFSUtils.getRootDir(conf); 072 URI defaultFs = hbasedir.getFileSystem(conf).getUri(); 073 CommonFSUtils.setFsDefault(conf, new Path(defaultFs)); 074 int ret = ToolRunner.run(conf, new RestoreDriver(), args); 075 System.exit(ret); 076 } 077 078 @Override 079 protected String getUsageString() { 080 return USAGE_STRING; 081 } 082}