use of org.apache.geode.admin.BackupStatus in project geode by apache.
the class SystemAdmin method backup.
public static void backup(String targetDir) throws AdminException {
InternalDistributedSystem ads = getAdminCnx();
// Baseline directory should be null if it was not provided on the command line
BackupStatus status = AdminDistributedSystemImpl.backupAllMembers(ads.getDistributionManager(), new File(targetDir), (SystemAdmin.baselineDir == null ? null : new File(SystemAdmin.baselineDir)));
boolean incomplete = !status.getOfflineDiskStores().isEmpty();
System.out.println("The following disk stores were backed up:");
for (Set<PersistentID> memberStores : status.getBackedUpDiskStores().values()) {
for (PersistentID store : memberStores) {
System.out.println("\t" + store);
}
}
if (incomplete) {
System.err.println("The backup may be incomplete. The following disk stores are not online:");
for (PersistentID store : status.getOfflineDiskStores()) {
System.err.println("\t" + store);
}
} else {
System.out.println("Backup successful.");
}
}
use of org.apache.geode.admin.BackupStatus in project geode by apache.
the class DiskStoreCommands method backupDiskStore.
@CliCommand(value = CliStrings.BACKUP_DISK_STORE, help = CliStrings.BACKUP_DISK_STORE__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
@ResourceOperation(resource = Resource.DATA, operation = Operation.READ)
public Result backupDiskStore(@CliOption(key = CliStrings.BACKUP_DISK_STORE__DISKDIRS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.BACKUP_DISK_STORE__DISKDIRS__HELP, mandatory = true) String targetDir, @CliOption(key = CliStrings.BACKUP_DISK_STORE__BASELINEDIR, help = CliStrings.BACKUP_DISK_STORE__BASELINEDIR__HELP) String baselineDir) {
Result result = null;
try {
InternalCache cache = getCache();
DM dm = cache.getDistributionManager();
BackupStatus backupStatus = null;
if (baselineDir != null && !baselineDir.isEmpty()) {
backupStatus = AdminDistributedSystemImpl.backupAllMembers(dm, new File(targetDir), new File(baselineDir));
} else {
backupStatus = AdminDistributedSystemImpl.backupAllMembers(dm, new File(targetDir), null);
}
Map<DistributedMember, Set<PersistentID>> backedupMemberDiskstoreMap = backupStatus.getBackedUpDiskStores();
Set<DistributedMember> backedupMembers = backedupMemberDiskstoreMap.keySet();
CompositeResultData crd = ResultBuilder.createCompositeResultData();
if (!backedupMembers.isEmpty()) {
SectionResultData backedupDiskStoresSection = crd.addSection();
backedupDiskStoresSection.setHeader(CliStrings.BACKUP_DISK_STORE_MSG_BACKED_UP_DISK_STORES);
TabularResultData backedupDiskStoresTable = backedupDiskStoresSection.addTable();
for (DistributedMember member : backedupMembers) {
Set<PersistentID> backedupDiskStores = backedupMemberDiskstoreMap.get(member);
boolean printMember = true;
String memberName = member.getName();
if (memberName == null || memberName.isEmpty()) {
memberName = member.getId();
}
for (PersistentID persistentId : backedupDiskStores) {
if (persistentId != null) {
String UUID = persistentId.getUUID().toString();
String hostName = persistentId.getHost().getHostName();
String directory = persistentId.getDirectory();
if (printMember) {
writeToBackupDisktoreTable(backedupDiskStoresTable, memberName, UUID, hostName, directory);
printMember = false;
} else {
writeToBackupDisktoreTable(backedupDiskStoresTable, "", UUID, hostName, directory);
}
}
}
}
} else {
SectionResultData noMembersBackedUp = crd.addSection();
noMembersBackedUp.setHeader(CliStrings.BACKUP_DISK_STORE_MSG_NO_DISKSTORES_BACKED_UP);
}
Set<PersistentID> offlineDiskStores = backupStatus.getOfflineDiskStores();
if (!offlineDiskStores.isEmpty()) {
SectionResultData offlineDiskStoresSection = crd.addSection();
TabularResultData offlineDiskStoresTable = offlineDiskStoresSection.addTable();
offlineDiskStoresSection.setHeader(CliStrings.BACKUP_DISK_STORE_MSG_OFFLINE_DISK_STORES);
for (PersistentID offlineDiskStore : offlineDiskStores) {
offlineDiskStoresTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_UUID, offlineDiskStore.getUUID().toString());
offlineDiskStoresTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_HOST, offlineDiskStore.getHost().getHostName());
offlineDiskStoresTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_DIRECTORY, offlineDiskStore.getDirectory());
}
}
result = ResultBuilder.buildResult(crd);
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
use of org.apache.geode.admin.BackupStatus in project geode by apache.
the class BackupDUnitTest method testBackupPRWithOfflineMembers.
@Test
public void testBackupPRWithOfflineMembers() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
LogWriterUtils.getLogWriter().info("Creating region in VM1");
createPersistentRegion(vm1);
LogWriterUtils.getLogWriter().info("Creating region in VM2");
createPersistentRegion(vm2);
createData(vm0, 0, 5, "A", "region1");
createData(vm0, 0, 5, "B", "region2");
closeCache(vm2);
BackupStatus status = backup(vm3);
assertEquals(2, status.getBackedUpDiskStores().size());
assertEquals(2, status.getOfflineDiskStores().size());
}
use of org.apache.geode.admin.BackupStatus in project geode by apache.
the class BackupDUnitTest method testBackupFromMemberWithDiskStore.
/**
* Test of bug 42419
*/
@Test
public void testBackupFromMemberWithDiskStore() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
LogWriterUtils.getLogWriter().info("Creating region in VM1");
createPersistentRegion(vm1);
createData(vm0, 0, 5, "A", "region1");
createData(vm0, 0, 5, "B", "region2");
BackupStatus status = backup(vm1);
assertEquals(2, status.getBackedUpDiskStores().size());
for (DistributedMember key : status.getBackedUpDiskStores().keySet()) {
assertNotNull(key);
}
assertEquals(Collections.emptySet(), status.getOfflineDiskStores());
validateBackupComplete();
closeCache(vm0);
closeCache(vm1);
// Destroy the current data
Invoke.invokeInEveryVM(new SerializableRunnable("Clean disk dirs") {
public void run() {
try {
cleanDiskDirs();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
restoreBackup(2);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
AsyncInvocation async0 = createPersistentRegionAsync(vm0);
LogWriterUtils.getLogWriter().info("Creating region in VM1");
AsyncInvocation async1 = createPersistentRegionAsync(vm1);
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
checkData(vm0, 0, 5, "A", "region1");
checkData(vm0, 0, 5, "B", "region2");
}
use of org.apache.geode.admin.BackupStatus in project geode by apache.
the class BackupDUnitTest method testBackupPR.
@Test
public void testBackupPR() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
LogWriterUtils.getLogWriter().info("Creating region in VM1");
createPersistentRegion(vm1);
long lm0 = setBackupFiles(vm0);
long lm1 = setBackupFiles(vm1);
createData(vm0, 0, 5, "A", "region1");
createData(vm0, 0, 5, "B", "region2");
BackupStatus status = backup(vm2);
assertEquals(2, status.getBackedUpDiskStores().size());
assertEquals(Collections.emptySet(), status.getOfflineDiskStores());
Pattern pattern = Pattern.compile(".*my.txt.*");
Collection<File> files = FileUtils.listFiles(getBackupDir(), new String[] { "txt" }, true);
assertEquals(4, files.size());
deleteOldUserUserFile(vm0);
deleteOldUserUserFile(vm1);
validateBackupComplete();
createData(vm0, 0, 5, "C", "region1");
createData(vm0, 0, 5, "C", "region2");
assertEquals(2, status.getBackedUpDiskStores().size());
assertEquals(Collections.emptySet(), status.getOfflineDiskStores());
closeCache(vm0);
closeCache(vm1);
// Destroy the current data
Invoke.invokeInEveryVM(new SerializableRunnable("Clean disk dirs") {
public void run() {
try {
cleanDiskDirs();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
restoreBackup(2);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
AsyncInvocation async0 = createPersistentRegionAsync(vm0);
LogWriterUtils.getLogWriter().info("Creating region in VM1");
AsyncInvocation async1 = createPersistentRegionAsync(vm1);
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
checkData(vm0, 0, 5, "A", "region1");
checkData(vm0, 0, 5, "B", "region2");
verifyUserFileRestored(vm0, lm0);
verifyUserFileRestored(vm1, lm1);
}
Aggregations