Skip to content

Commit bf805d1

Browse files
nathanejohnsonGabrielBrascher
authored andcommitted
Add back ability to disable backup of snapshot to secondary (#3122)
* 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 * updates per review
1 parent 463372b commit bf805d1

4 files changed

Lines changed: 37 additions & 6 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.cloudstack.engine.subsystem.api.storage;
1818

1919
import com.cloud.storage.Snapshot;
20+
import com.cloud.utils.exception.CloudRuntimeException;
2021

2122
public interface SnapshotInfo extends DataObject, Snapshot {
2223
SnapshotInfo getParent();
@@ -42,4 +43,6 @@ public interface SnapshotInfo extends DataObject, Snapshot {
4243
boolean isRevertable();
4344

4445
long getPhysicalSize();
46+
47+
void markBackedUp() throws CloudRuntimeException;
4548
}

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 void markBackedUp() throws CloudRuntimeException{
154+
try {
155+
processEvent(Event.OperationNotPerformed);
156+
} catch (NoTransitionException ex) {
157+
s_logger.error("no transition error: ", ex);
158+
throw new CloudRuntimeException("Error marking snapshot backed up: " +
159+
this.snapshot.getId() + " " + ex.getMessage());
160+
}
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: 20 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,13 +1123,16 @@ 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 backupSnapToSecondary = BackupSnapshotAfterTakingSnapshot.value() == null ||
1127+
BackupSnapshotAfterTakingSnapshot.value();
1128+
1129+
if (backupSnapToSecondary) {
1130+
backupSnapshotToSecondary(payload.getAsyncBackup(), snapshotStrategy, snapshotOnPrimary);
11281131
} else {
1129-
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshotOnPrimary);
1130-
if (backupedSnapshot != null) {
1131-
snapshotStrategy.postSnapshotCreation(snapshotOnPrimary);
1132+
if(s_logger.isDebugEnabled()) {
1133+
s_logger.debug("skipping backup of snapshot " + snapshotId + " to secondary due to configuration");
11321134
}
1135+
snapshotOnPrimary.markBackedUp();
11331136
}
11341137

11351138
try {
@@ -1171,6 +1174,17 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
11711174
return snapshot;
11721175
}
11731176

1177+
protected void backupSnapshotToSecondary(boolean asyncBackup, SnapshotStrategy snapshotStrategy, SnapshotInfo snapshotOnPrimary) {
1178+
if (asyncBackup) {
1179+
backupSnapshotExecutor.schedule(new BackupSnapshotTask(snapshotOnPrimary, snapshotBackupRetries - 1, snapshotStrategy), 0, TimeUnit.SECONDS);
1180+
} else {
1181+
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshotOnPrimary);
1182+
if (backupedSnapshot != null) {
1183+
snapshotStrategy.postSnapshotCreation(snapshotOnPrimary);
1184+
}
1185+
}
1186+
}
1187+
11741188
protected class BackupSnapshotTask extends ManagedContextRunnable {
11751189
SnapshotInfo snapshot;
11761190
int attempts;

0 commit comments

Comments
 (0)