CacheSnapshotService (Apache Geode 1.6.0)
Date: 2018-04-23

org.apache.geode.cache.snapshot

## Interface CacheSnapshotService

-     public interface CacheSnapshotService

  Allows a snapshot of cache data to be imported and exported. Each region in the cache will be included in the snapshot, one snapshot file (.gfd) for each region. Example usage:

       // obtain a snapshot
       CacheSnapshotService snapshot = cache.getSnapshotService();

       // export the snapshot, every region in the cache will be exported
       snapshot.save(new File("."), SnapshotFormat.GEMFIRE);

       // import the snapshot files, updates any existing entries in the cache
       snapshot.load(new File("."), SnapshotFormat.GEMFIRE);

  The default behavior is to perform all I/O operations on the node where the snapshot operations are invoked. This will involve either collecting or dispersing data over the network if the cache contains a partitioned region. The snapshot behavior can be changed using `SnapshotOptions`. For example:

       CacheSnapshotService snapshot = cache.getSnapshotService();
       SnapshotFilter filter = new SnapshotFilter() {
         public boolean accept(Entry entry) {
           return true;
         }
       };

       SnapshotOptions options = snapshot.createOptions();
       options.setFilter(filter);

       snapshot.save(new File("."), SnapshotFormat.GEMFIRE, options);

  When the parallel snapshot option is used for export, a file for each region will be created on every member that contains data for that region and the file name will include a unique identifier for the member that created the file. When loading a snapshot created using parallel mode, either the files from all members can be combined into a directory to load from on a single member or files can be distributed across any number of members and imported using the parallel snapshot option, provided the files are in the same directory on each member. Note that the snapshot does not provide a consistency guarantee. Updates to data during the course of import/export operations could result data inconsistencies.
  Since:
    GemFire 7.0
  See Also:
    `Cache.getSnapshotService()`, `SnapshotOptions`

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `SnapshotOptions<java.lang.Object,java.lang.Object>` | `createOptions()` Creates a `SnapshotOptions` object configured with default settings.
    `void` | `load(java.io.File[] snapshots, SnapshotOptions.SnapshotFormat format, SnapshotOptions<java.lang.Object,java.lang.Object> options)` Imports the specified snapshot files into the cache by applying user-configured options.
    `void` | `load(java.io.File dir, SnapshotOptions.SnapshotFormat format)` Imports all snapshot files (*.gfd) in the specified directory into the cache.
    `void` | `save(java.io.File dir, SnapshotOptions.SnapshotFormat format)` Exports all regions in the cache to the specified directory.
    `void` | `save(java.io.File dir, SnapshotOptions.SnapshotFormat format, SnapshotOptions<java.lang.Object,java.lang.Object> options)` Exports all regions in the cache to the specified directory by applying user-configured options.

- - ### Method Detail

    - #### createOptions

          SnapshotOptions<java.lang.Object,java.lang.Object> createOptions()

      Creates a `SnapshotOptions` object configured with default settings. The options can be used to configure snapshot behavior.
      Returns:
        the default options

    - #### save

          void save(java.io.File dir,
                    SnapshotOptions.SnapshotFormat format)
             throws java.io.IOException

      Exports all regions in the cache to the specified directory. The cache entries in each region will be written to a separate file.
      Parameters:
        `dir` - the directory for writing the snapshots, will be created if necessary
        `format` - the snapshot format
      Throws:
        `java.io.IOException` - error writing snapshot

    - #### save

          void save(java.io.File dir,
                    SnapshotOptions.SnapshotFormat format,
                    SnapshotOptions<java.lang.Object,java.lang.Object> options)
             throws java.io.IOException

      Exports all regions in the cache to the specified directory by applying user-configured options. The cache entries in each region will be written to a separate file.
      Parameters:
        `dir` - the directory for writing the snapshots, will be created if necessary
        `format` - the snapshot format
        `options` - the snapshot options
      Throws:
        `java.io.IOException` - error writing snapshot

    - #### load

          void load(java.io.File dir,
                    SnapshotOptions.SnapshotFormat format)
             throws java.io.IOException,
                    java.lang.ClassNotFoundException

      Imports all snapshot files (*.gfd) in the specified directory into the cache. The cache entries in a given snapshot file are loaded into the same region they were originally exported from (based on a corresponding region name). Files that do not match the supplied snapshot format will cause an import error.

      Prior to loading data, all regions should have been created and any necessary serializers (either `DataSerializer` or `PdxSerializer`) and `Instantiator`s should have been registered.

      Parameters:
        `dir` - the directory containing the snapshot files
        `format` - the snapshot file format
      Throws:
        `java.io.IOException` - Unable to import data
        `java.lang.ClassNotFoundException` - Unable to import data

    - #### load

          void load(java.io.File[] snapshots,
                    SnapshotOptions.SnapshotFormat format,
                    SnapshotOptions<java.lang.Object,java.lang.Object> options)
             throws java.io.IOException,
                    java.lang.ClassNotFoundException

      Imports the specified snapshot files into the cache by applying user-configured options. Each file must have the snapshot file extension (.gfd). The cache entries in a given snapshot file are loaded into the same region they were originally exported from (based on a corresponding region name). Files that do not match the supplied snapshot format will cause an import error.

      Prior to loading data, all regions should have been created and any necessary serializers (either `DataSerializer` or `PdxSerializer`) and `Instantiator`s should have been registered.

      Parameters:
        `snapshots` - the snapshot files
        `format` - the snapshot file format
        `options` - the snapshot options
      Throws:
        `java.io.IOException` - Unable to import data
        `java.lang.ClassNotFoundException` - Unable to import data