private void executeSnapshot()

in priam/src/main/java/com/netflix/priam/backup/SnapshotBackup.java [114:164]


    private void executeSnapshot() throws Exception {
        Date startTime = Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime();
        snapshotName = DateUtil.formatyyyyMMddHHmm(startTime);
        snapshotInstant = DateUtil.getInstant();
        String token = instanceIdentity.getInstance().getToken();

        // Save start snapshot status
        BackupMetadata backupMetadata =
                new BackupMetadata(BackupVersion.SNAPSHOT_BACKUP, token, startTime);
        snapshotStatusMgr.start(backupMetadata);

        try {
            logger.info("Starting snapshot {}", snapshotName);
            cassandraOperations.takeSnapshot(snapshotName);
            backupMetadata.setCassandraSnapshotSuccess(true);

            // Collect all snapshot dir's under keyspace dir's
            abstractBackupPaths = Lists.newArrayList();
            // Try to upload all the files as part of snapshot. If there is any error, there will be
            // an exception and snapshot will be considered as failure.
            initiateBackup(SNAPSHOT_FOLDER, backupRestoreUtil);

            // All the files are uploaded successfully as part of snapshot.
            // pre condition notify of meta.json upload
            File tmpMetaFile = metaData.createTmpMetaFile();
            // Note: no need to remove this temp as it is done within createTmpMetaFile()
            AbstractBackupPath metaJsonAbp = metaData.decorateMetaJson(tmpMetaFile, snapshotName);

            // Upload meta file
            AbstractBackupPath metaJson = metaData.set(abstractBackupPaths, snapshotName);

            logger.info("Snapshot upload complete for {}", snapshotName);
            backupMetadata.setSnapshotLocation(
                    config.getBackupPrefix() + File.separator + metaJson.getRemotePath());
            snapshotStatusMgr.finish(backupMetadata);
        } catch (Exception e) {
            logger.error(
                    "Exception occurred while taking snapshot: {}. Exception: {}",
                    snapshotName,
                    e.getLocalizedMessage());
            e.printStackTrace();
            snapshotStatusMgr.failed(backupMetadata);
            throw e;
        } finally {
            try {
                cassandraOperations.clearSnapshot(snapshotName);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }