Search in sources :

Example 1 with BackupStatus

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.");
    }
}
Also used : BackupStatus(org.apache.geode.admin.BackupStatus) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 2 with BackupStatus

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) DM(org.apache.geode.distributed.internal.DM) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) CacheExistsException(org.apache.geode.cache.CacheExistsException) MemberNotFoundException(org.apache.geode.management.internal.cli.util.MemberNotFoundException) DiskStoreNotFoundException(org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) File(java.io.File) BackupStatus(org.apache.geode.admin.BackupStatus) PersistentID(org.apache.geode.cache.persistence.PersistentID) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 3 with BackupStatus

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());
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) BackupStatus(org.apache.geode.admin.BackupStatus) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 4 with BackupStatus

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");
}
Also used : VM(org.apache.geode.test.dunit.VM) DistributedMember(org.apache.geode.distributed.DistributedMember) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) BackupStatus(org.apache.geode.admin.BackupStatus) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 5 with BackupStatus

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);
}
Also used : Pattern(java.util.regex.Pattern) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) File(java.io.File) BackupStatus(org.apache.geode.admin.BackupStatus) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

BackupStatus (org.apache.geode.admin.BackupStatus)13 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 Test (org.junit.Test)7 IOException (java.io.IOException)6 Host (org.apache.geode.test.dunit.Host)6 VM (org.apache.geode.test.dunit.VM)6 AdminDistributedSystem (org.apache.geode.admin.AdminDistributedSystem)4 AdminException (org.apache.geode.admin.AdminException)4 DistributedSystemConfig (org.apache.geode.admin.DistributedSystemConfig)4 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)4 File (java.io.File)3 PersistentID (org.apache.geode.cache.persistence.PersistentID)3 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)3 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)3 HashSet (java.util.HashSet)2 DistributedMember (org.apache.geode.distributed.DistributedMember)2 FileNotFoundException (java.io.FileNotFoundException)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1