use of com.emc.vipr.model.sys.backup.BackupInfo in project coprhd-controller by CoprHD.
the class BackupOps method getBackupInfo.
/**
* Query info of a remote backup, if the backup has been downloaded, get info from local downloaded directory
* @param backupName
* @param client
* @return
* @throws IOException
*/
public BackupInfo getBackupInfo(String backupName, BackupClient client) throws Exception {
log.info("To get backup info of {} from server={} ", backupName, client.getUri());
BackupInfo backupInfo = new BackupInfo();
try {
long size = client.getFileSize(backupName);
backupInfo.setBackupSize(size);
} catch (Exception e) {
log.warn("Failed to get the backup file size, e=", e);
throw BackupException.fatals.failedToGetBackupSize(backupName, e);
}
InputStream in = client.download(backupName);
ZipInputStream zin = new ZipInputStream(in);
ZipEntry zentry = zin.getNextEntry();
while (zentry != null) {
if (isPropEntry(zentry)) {
log.info("Found the property file={}", zentry.getName());
setBackupInfo(backupInfo, backupName, zin);
break;
}
zentry = zin.getNextEntry();
}
try {
zin.closeEntry();
zin.close();
} catch (IOException e) {
log.debug("Failed to close the stream e", e);
// it's a known issue to use curl
// it's safe to ignore this exception here.
}
BackupRestoreStatus s = queryBackupRestoreStatus(backupName, true);
backupInfo.setRestoreStatus(s);
return backupInfo;
}
use of com.emc.vipr.model.sys.backup.BackupInfo in project coprhd-controller by CoprHD.
the class BackupManager method queryBackupInfo.
@Override
public BackupInfo queryBackupInfo(String backupName) {
log.info("To query backup {}", backupName);
checkBackupDir();
BackupInfo backupInfo = new BackupInfo();
backupInfo.setBackupName(backupName);
File backupRootDir = backupContext.getBackupDir();
File backupDir = new File(backupRootDir, backupName);
if (!backupDir.isDirectory()) {
log.error("The {} is not a directory", backupDir.getAbsolutePath());
return backupInfo;
}
File[] backupFiles = backupDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(BackupConstants.COMPRESS_SUFFIX) || name.endsWith(BackupConstants.BACKUP_INFO_SUFFIX);
}
});
if (backupFiles == null || backupFiles.length == 0) {
log.info("The {} has no backup files", backupDir.getAbsolutePath());
return backupInfo;
}
long size = 0;
for (File file : backupFiles) {
if (file.getName().endsWith(BackupConstants.BACKUP_INFO_SUFFIX)) {
log.info("Get the create time from info file {}", file.getName());
BackupOps ops = new BackupOps();
try (FileInputStream in = new FileInputStream(file)) {
ops.setBackupInfo(backupInfo, backupName, in);
} catch (IOException e) {
log.error("Failed to read info file {}", file.getAbsolutePath());
return backupInfo;
}
}
size += file.length();
}
backupInfo.setBackupSize(size);
log.info("Query backup successfully: {}", backupInfo);
return backupInfo;
}
use of com.emc.vipr.model.sys.backup.BackupInfo in project coprhd-controller by CoprHD.
the class BackupOps method queryBackupFromNode.
private BackupInfo queryBackupFromNode(String backupName, String host, int port) {
JMXConnector conn = connect(host, port);
try {
BackupManagerMBean backupMBean = getBackupManagerMBean(conn);
BackupInfo backupInfo = backupMBean.queryBackupInfo(backupName);
if (backupInfo == null) {
throw new IllegalStateException(String.format("Get backup info of %s returns null", backupName));
}
log.info("Node({}:{}) - Get backup info {} success", new Object[] { host, port, backupName });
log.info("backupInfo={}", backupInfo);
return backupInfo;
} catch (BackupException e) {
log.error("Node({}:{}) - Query backup info {} failed", host, port, backupName);
throw e;
} finally {
close(conn);
}
}
use of com.emc.vipr.model.sys.backup.BackupInfo in project coprhd-controller by CoprHD.
the class BackupOps method queryLocalBackupInfo.
public BackupInfo queryLocalBackupInfo(String backupTag) {
BackupInfo backupInfo = new BackupInfo();
backupInfo.setBackupName(backupTag);
for (int retryCnt = 0; retryCnt < BackupConstants.RETRY_MAX_CNT; retryCnt++) {
try {
BackupRestoreStatus s = queryBackupRestoreStatus(backupTag, true);
backupInfo.setRestoreStatus(s);
List<BackupProcessor.BackupTask<BackupInfo>> backupTasks = new BackupProcessor(getHosts(), Arrays.asList(ports.get(2)), backupTag).process(new QueryBackupCallable(), true);
for (BackupProcessor.BackupTask task : backupTasks) {
BackupInfo backupInfoFromNode = (BackupInfo) task.getResponse().getFuture().get();
log.info("Query backup({}) success", backupTag);
mergeBackupInfo(backupInfo, backupInfoFromNode);
}
} catch (RetryableBackupException e) {
log.info("Retry to query backup {}", backupTag);
continue;
} catch (Exception e) {
log.warn("Query local backup({}) info got an error", backupTag, e);
}
break;
}
return backupInfo;
}
use of com.emc.vipr.model.sys.backup.BackupInfo in project coprhd-controller by CoprHD.
the class Backup method externalItemsJson.
/**
* Only get the remote backup info
* @param ids
*/
@Restrictions({ @Restrict("SYSTEM_ADMIN"), @Restrict("SYSTEM_MONITOR"), @Restrict("RESTRICTED_SYSTEM_ADMIN") })
public static void externalItemsJson(@As(",") String[] ids) {
List<BackupDataTable.Backup> results = Lists.newArrayList();
if (ids != null) {
for (String id : ids) {
if (StringUtils.isNotBlank(id)) {
BackupInfo backupInfo = BackupUtils.getBackupInfo(id, false);
BackupDataTable.Backup backup = new BackupDataTable.Backup(id, false);
backup.creationtime = backupInfo.getCreateTime();
backup.sitename = backupInfo.getSiteName();
backup.version = backupInfo.getVersion();
backup.size = backupInfo.getBackupSize();
results.add(backup);
}
}
}
renderJSON(results);
}
Aggregations