use of org.apache.geode.admin.internal.BackupDataStoreResult in project geode by apache.
the class DistributedSystemBridge method backupAllMembers.
/**
*
* @param targetDirPath path of the directory where the back up files should be placed.
* @param baselineDirPath path of the directory for baseline backup.
* @return open type DiskBackupStatus containing each member wise disk back up status
*/
public DiskBackupStatus backupAllMembers(String targetDirPath, String baselineDirPath) throws Exception {
if (BackupDataStoreHelper.obtainLock(dm)) {
try {
if (targetDirPath == null || targetDirPath.isEmpty()) {
throw new Exception(ManagementStrings.TARGET_DIR_CANT_BE_NULL_OR_EMPTY.toLocalizedString());
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
File targetDir = new File(targetDirPath);
targetDir = new File(targetDir, format.format(new Date()));
File baselineDir = null;
if (baselineDirPath != null) {
baselineDir = new File(baselineDirPath);
}
DM dm = cache.getDistributionManager();
Set<PersistentID> missingMembers = MissingPersistentIDsRequest.send(dm);
Set recipients = dm.getOtherDistributionManagerIds();
BackupDataStoreResult result = BackupDataStoreHelper.backupAllMembers(dm, recipients, targetDir, baselineDir);
Iterator<DistributedMember> it = result.getSuccessfulMembers().keySet().iterator();
Map<String, String[]> backedUpDiskStores = new HashMap<>();
while (it.hasNext()) {
DistributedMember member = it.next();
Set<PersistentID> setOfDisk = result.getSuccessfulMembers().get(member);
String[] setOfDiskStr = new String[setOfDisk.size()];
int j = 0;
for (PersistentID id : setOfDisk) {
setOfDiskStr[j] = id.getDirectory();
j++;
}
backedUpDiskStores.put(member.getId(), setOfDiskStr);
}
// should override the previous missingMembers
for (Set<PersistentID> onlineMembersIds : result.getSuccessfulMembers().values()) {
missingMembers.removeAll(onlineMembersIds);
}
result.getExistingDataStores().keySet().removeAll(result.getSuccessfulMembers().keySet());
String[] setOfMissingDiskStr = null;
if (result.getExistingDataStores().size() > 0) {
setOfMissingDiskStr = new String[result.getExistingDataStores().size()];
int j = 0;
for (Set<PersistentID> lostMembersIds : result.getExistingDataStores().values()) {
for (PersistentID id : lostMembersIds) {
setOfMissingDiskStr[j] = id.getDirectory();
j++;
}
}
}
DiskBackupStatus diskBackupStatus = new DiskBackupStatus();
diskBackupStatus.setBackedUpDiskStores(backedUpDiskStores);
diskBackupStatus.setOfflineDiskStores(setOfMissingDiskStr);
return diskBackupStatus;
} finally {
BackupDataStoreHelper.releaseLock(dm);
}
} else {
throw new Exception(LocalizedStrings.DistributedSystem_BACKUP_ALREADY_IN_PROGRESS.toLocalizedString());
}
}
Aggregations