SnapshotVO prevSnapshot = null;
String prevSnapshotUuid = null;
String prevBackupUuid = null;
SwiftTO swift = _swiftMgr.getSwiftTO();
S3TO s3 = _s3Mgr.getS3TO();
checkObjectStorageConfiguration(swift, s3);
long prevSnapshotId = snapshot.getPrevSnapshotId();
if (prevSnapshotId > 0) {
prevSnapshot = _snapshotDao.findByIdIncludingRemoved(prevSnapshotId);
if ( prevSnapshot.getBackupSnapshotId() != null && swift == null) {
if (prevSnapshot.getVersion() != null && prevSnapshot.getVersion().equals("2.2")) {
prevBackupUuid = prevSnapshot.getBackupSnapshotId();
prevSnapshotUuid = prevSnapshot.getPath();
}
} else if ((prevSnapshot.getSwiftId() != null && swift != null)
|| (prevSnapshot.getS3Id() != null && s3 != null)) {
prevBackupUuid = prevSnapshot.getBackupSnapshotId();
prevSnapshotUuid = prevSnapshot.getPath();
}
}
boolean isVolumeInactive = _storageMgr.volumeInactive(volume);
String vmName = _storageMgr.getVmNameOnVolume(volume);
StoragePoolVO srcPool = _storagePoolDao.findById(volume.getPoolId());
BackupSnapshotCommand backupSnapshotCommand = new BackupSnapshotCommand(secondaryStoragePoolUrl, dcId, accountId, volumeId, snapshot.getId(), volume.getPath(), srcPool, snapshotUuid,
snapshot.getName(), prevSnapshotUuid, prevBackupUuid, isVolumeInactive, vmName, _backupsnapshotwait);
if ( swift != null ) {
backupSnapshotCommand.setSwift(swift);
} else if (s3 != null) {
backupSnapshotCommand.setS3(s3);
}
String backedUpSnapshotUuid = null;
// By default, assume failed.
boolean backedUp = false;
BackupSnapshotAnswer answer = (BackupSnapshotAnswer) sendToPool(volume, backupSnapshotCommand);
if (answer != null && answer.getResult()) {
backedUpSnapshotUuid = answer.getBackupSnapshotName();
if (backedUpSnapshotUuid != null) {
backedUp = true;
}
} else if (answer != null) {
s_logger.error(answer.getDetails());
}
// Update the status in all cases.
Transaction txn = Transaction.currentTxn();
txn.start();
if (backedUp) {
if (backupSnapshotCommand.getSwift() != null ) {
snapshot.setSwiftId(swift.getId());
snapshot.setBackupSnapshotId(backedUpSnapshotUuid);
} else if (backupSnapshotCommand.getS3() != null) {
snapshot.setS3Id(s3.getId());
snapshot.setBackupSnapshotId(backedUpSnapshotUuid);
} else {