Exporting Cache and Region Snapshots
To save GemFire cache or region data to a snapshot that you can later load into another distributed system or region, use the
region.getSnapshotService.save API, or the
gfsh command-line interface (
If an error occurs during export, the export halts and the snapshot operation is canceled. Typical errors that halt an export include scenarios such as full disk, problems with file permissions, and network partitioning.
When you export an entire cache, it exports all regions in the cache as individual snapshot files into a directory. If no directory is specified, the default is the current directory. A snapshot file is created for each region, and the export operation automatically names each snapshot filename using the following convention:
When the export operation writes the snapshot filename, it replaces each forward slash (’/’) in the region path with a dash (’-’).
Using Java API:
File mySnapshotDir = ... Cache cache = ... cache.getSnapshotService().save(mySnapshotDir, SnapshotFormat.GEMFIRE);
Optionally, you can set a filter on the snapshot entries during the export. See Filtering Entries During Import or Export for an example.
You can also export a specific region using the following API or gfsh commands:
File mySnapshot = ... Region<String, MyObject> region = ... region.getSnapshotService().save(mySnapshot, SnapshotFormat.GEMFIRE);
Open a gfsh prompt. After connecting to a GemFire distributed system, at the prompt type:
gfsh>export data --region=Region --file=FileName.gfd --member=MemberName
where Region corresponds to the name of the region that you want to export, FileName (must end in .gfd) corresponds to the name of the export file and MemberName corresponds to a member that hosts the region. For example:
gfsh>export data --region=region1 --file=region1_2012_10_10.gfd --member=server1
The snapshot file will be written on the remote member at the location specified by the
--file argument. For example, in the example command above, the
region1_2012_10_10.gfd file will be written in the working directory of
server1. For more information on this command, see export data.
These examples show how to include the
parallel option for exporting partitioned regions.
Note that the
parallel option takes a directory rather than a file; see export data for details.
File mySnapshotDir = ... Region<String, MyObject> region = ... SnapshotOptions<Integer, MyObject> options = region.getSnapshotServive.createOptions().setParallelMode(true); region.getSnapshotService().save(mySnapshotDir, SnapshotFormat.GEMFIRE, options);
The Java API example, above, accomplishes the same purpose as the following gfsh command:
gfsh>export data --parallel --region=region1 --dir=region1_2012_10_10 --member=server1