Search in sources :

Example 1 with BackupInfo

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;
}
Also used : BackupInfo(com.emc.vipr.model.sys.backup.BackupInfo) ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BackupRestoreStatus(com.emc.vipr.model.sys.backup.BackupRestoreStatus) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CancellationException(java.util.concurrent.CancellationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) RetryableBackupException(com.emc.storageos.management.backup.exceptions.RetryableBackupException) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) BackupException(com.emc.storageos.management.backup.exceptions.BackupException)

Example 2 with 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;
}
Also used : BackupInfo(com.emc.vipr.model.sys.backup.BackupInfo) FilenameFilter(java.io.FilenameFilter) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with 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);
    }
}
Also used : BackupInfo(com.emc.vipr.model.sys.backup.BackupInfo) RetryableBackupException(com.emc.storageos.management.backup.exceptions.RetryableBackupException) BackupException(com.emc.storageos.management.backup.exceptions.BackupException) JMXConnector(javax.management.remote.JMXConnector)

Example 4 with BackupInfo

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;
}
Also used : BackupInfo(com.emc.vipr.model.sys.backup.BackupInfo) BackupRestoreStatus(com.emc.vipr.model.sys.backup.BackupRestoreStatus) RetryableBackupException(com.emc.storageos.management.backup.exceptions.RetryableBackupException) URISyntaxException(java.net.URISyntaxException) CancellationException(java.util.concurrent.CancellationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) RetryableBackupException(com.emc.storageos.management.backup.exceptions.RetryableBackupException) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) BackupException(com.emc.storageos.management.backup.exceptions.BackupException)

Example 5 with 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);
}
Also used : BackupInfo(com.emc.vipr.model.sys.backup.BackupInfo) BackupDataTable(models.datatable.BackupDataTable) Restrictions(controllers.deadbolt.Restrictions)

Aggregations

BackupInfo (com.emc.vipr.model.sys.backup.BackupInfo)6 BackupException (com.emc.storageos.management.backup.exceptions.BackupException)3 RetryableBackupException (com.emc.storageos.management.backup.exceptions.RetryableBackupException)3 IOException (java.io.IOException)3 BackupRestoreStatus (com.emc.vipr.model.sys.backup.BackupRestoreStatus)2 FileInputStream (java.io.FileInputStream)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 UnknownHostException (java.net.UnknownHostException)2 CancellationException (java.util.concurrent.CancellationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 KeeperException (org.apache.zookeeper.KeeperException)2 BackupSet (com.emc.vipr.model.sys.backup.BackupSets.BackupSet)1 Restrictions (controllers.deadbolt.Restrictions)1 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ZipEntry (java.util.zip.ZipEntry)1