Skip to content

Commit 816a356

Browse files
The snapshot.backup.rightafter configuration variable was removed by:
SHA: 6bb0ca2 This adds it back, though named snapshot.backup.to.secondary now instead. This global parameter, once set, will allow you to prevent automatic backups of snapshots to secondary storage, unless they're actually needed. Fixes #3096
1 parent e56c499 commit 816a356

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ public interface SnapshotInfo extends DataObject, Snapshot {
4242
boolean isRevertable();
4343

4444
long getPhysicalSize();
45+
46+
boolean markBackedUp();
4547
}

engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ public long getPhysicalSize() {
149149
return physicalSize;
150150
}
151151

152+
@Override
153+
public boolean markBackedUp() {
154+
try {
155+
processEvent(Event.OperationNotPerformed);
156+
} catch (NoTransitionException ex) {
157+
s_logger.error("no transition error: ", ex);
158+
return false;
159+
}
160+
return true;
161+
}
162+
152163
@Override
153164
public VolumeInfo getBaseVolume() {
154165
return volFactory.getVolume(snapshot.getVolumeId());

server/src/com/cloud/storage/snapshot/SnapshotManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public interface SnapshotManager extends Configurable {
5656
public static final ConfigKey<Integer> BackupRetryInterval = new ConfigKey<Integer>(Integer.class, "backup.retry.interval", "Advanced", "300",
5757
"Time in seconds between retries in backing up snapshot to secondary", false, ConfigKey.Scope.Global, null);
5858

59+
public static final ConfigKey<Boolean> BackupSnapshotAfterTakingSnapshot = new ConfigKey<Boolean>(Boolean.class, "snapshot.backup.to.secondary", "Snapshots", "true",
60+
"Indicates whether to always backup primary storage snapshot to secondary storage", false, ConfigKey.Scope.Global, null);
61+
5962
void deletePoliciesForVolume(Long volumeId);
6063

6164
/**

server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public String getConfigComponentName() {
206206

207207
@Override
208208
public ConfigKey<?>[] getConfigKeys() {
209-
return new ConfigKey<?>[] {BackupRetryAttempts, BackupRetryInterval, SnapshotHourlyMax, SnapshotDailyMax, SnapshotMonthlyMax, SnapshotWeeklyMax, usageSnapshotSelection};
209+
return new ConfigKey<?>[] {BackupRetryAttempts, BackupRetryInterval, SnapshotHourlyMax, SnapshotDailyMax, SnapshotMonthlyMax, SnapshotWeeklyMax, usageSnapshotSelection, BackupSnapshotAfterTakingSnapshot};
210210
}
211211

212212
@Override
@@ -1123,12 +1123,24 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
11231123
}
11241124

11251125
SnapshotInfo snapshotOnPrimary = snapshotStrategy.takeSnapshot(snapshot);
1126-
if (payload.getAsyncBackup()) {
1127-
backupSnapshotExecutor.schedule(new BackupSnapshotTask(snapshotOnPrimary, snapshotBackupRetries - 1, snapshotStrategy), 0, TimeUnit.SECONDS);
1126+
boolean backupFlag = BackupSnapshotAfterTakingSnapshot.value() == null ||
1127+
BackupSnapshotAfterTakingSnapshot.value();
1128+
1129+
if (backupFlag) {
1130+
if (payload.getAsyncBackup()) {
1131+
backupSnapshotExecutor.schedule(new BackupSnapshotTask(snapshotOnPrimary, snapshotBackupRetries - 1, snapshotStrategy), 0, TimeUnit.SECONDS);
1132+
} else {
1133+
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshotOnPrimary);
1134+
if (backupedSnapshot != null) {
1135+
snapshotStrategy.postSnapshotCreation(snapshotOnPrimary);
1136+
}
1137+
}
11281138
} else {
1129-
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshotOnPrimary);
1130-
if (backupedSnapshot != null) {
1131-
snapshotStrategy.postSnapshotCreation(snapshotOnPrimary);
1139+
if(s_logger.isDebugEnabled()) {
1140+
s_logger.debug("skipping backup of snapshot to secondary due to configuration");
1141+
}
1142+
if (!snapshotOnPrimary.markBackedUp()) {
1143+
throw new CloudRuntimeException("Can't mark snapshot as backed up!");
11321144
}
11331145
}
11341146

0 commit comments

Comments
 (0)