You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by lg...@apache.org on 2017/09/21 16:23:24 UTC

[geode] branch feature/GEODE-3187 updated (5626fe7 -> a5d919d)

This is an automated email from the ASF dual-hosted git repository.

lgallinat pushed a change to branch feature/GEODE-3187
in repository https://gitbox.apache.org/repos/asf/geode.git.


 discard 5626fe7  GEODE-3187 Fix backup inspector and restore script for windows. Refactor RestoreScript.java and BackupInspector.java
     new a5d919d  GEODE-3187 Fix backup inspector and restore script for windows. Refactor RestoreScript.java and BackupInspector.java

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (5626fe7)
            \
             N -- N -- N   refs/heads/feature/GEODE-3187 (a5d919d)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../BackupInspectorIntegrationTest.java            | 53 +---------------------
 1 file changed, 1 insertion(+), 52 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].

[geode] 01/01: GEODE-3187 Fix backup inspector and restore script for windows. Refactor RestoreScript.java and BackupInspector.java

Posted by lg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lgallinat pushed a commit to branch feature/GEODE-3187
in repository https://gitbox.apache.org/repos/asf/geode.git

commit a5d919d4bc0037ff80665953e03afeb3cf8747b9
Author: Lynn Gallinat <lg...@pivotal.io>
AuthorDate: Wed Sep 20 16:09:43 2017 -0700

    GEODE-3187 Fix backup inspector and restore script for windows.
    Refactor RestoreScript.java and BackupInspector.java
---
 .../cache/persistence/BackupInspector.java         | 219 ++-----------------
 .../internal/cache/persistence/RestoreScript.java  | 236 +++++++--------------
 .../cache/persistence/ScriptGenerator.java         |  37 ++++
 .../cache/persistence/UnixBackupInspector.java     |  78 +++++++
 .../cache/persistence/UnixScriptGenerator.java     |  58 +++++
 .../cache/persistence/WindowsBackupInspector.java  |  86 ++++++++
 .../cache/persistence/WindowsScriptGenerator.java  |  76 +++++++
 .../BackupInspectorIntegrationTest.java            | 171 +++++++++++++++
 .../persistence/BackupInspectorJUnitTest.java      | 225 --------------------
 9 files changed, 604 insertions(+), 582 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/BackupInspector.java b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/BackupInspector.java
index bb37889..270932e 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/BackupInspector.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/BackupInspector.java
@@ -24,6 +24,8 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.geode.internal.lang.SystemUtils;
+
 /**
  * Inspects a completed backup and parses the operation log file data from the restore script
  * produced by a previous backup.
@@ -34,17 +36,17 @@ public abstract class BackupInspector {
    * files. These lines will be added to future restore scripts if the operation logs are still
    * relevant to the member.
    */
-  protected Map<String, String> oplogLineMap = new HashMap<String, String>();
+  final Map<String, String> oplogLineMap = new HashMap<>();
 
   /**
    * Contains the unique set of operation log file names contained in the restore script.
    */
-  protected Set<String> oplogFileNames = new HashSet<String>();
+  final Set<String> oplogFileNames = new HashSet<>();
 
   /**
    * Root directory for a member's backup.
    */
-  protected File backupDir = null;
+  private final File backupDir;
 
   /**
    * Returns a BackupInspector for a member's backup directory.
@@ -53,8 +55,8 @@ public abstract class BackupInspector {
    * @return a new BackupInspector.
    * @throws IOException the backup directory was malformed.
    */
-  public static BackupInspector createInspector(File backupDir) throws IOException {
-    if (isWindows()) {
+  public static BackupInspector createInspector(final File backupDir) throws IOException {
+    if (SystemUtils.isWindows()) {
       return new WindowsBackupInspector(backupDir);
     }
 
@@ -67,44 +69,34 @@ public abstract class BackupInspector {
    * @param backupDir a a previous backup for a member.
    * @throws IOException an error occurred while parsing the restore script.
    */
-  public BackupInspector(File backupDir) throws IOException {
-    this.backupDir = backupDir;
-
+  BackupInspector(final File backupDir) throws IOException {
     if (!backupDir.exists()) {
       throw new IOException("Backup directory " + backupDir.getAbsolutePath() + " does not exist.");
     }
 
-    File restoreFile = getRestoreFile(backupDir);
+    this.backupDir = backupDir;
 
+    File restoreFile = getRestoreFile(backupDir);
     if (!restoreFile.exists()) {
       throw new IOException("Restore file " + restoreFile.getName() + " does not exist.");
     }
 
-    BufferedReader reader = null;
-
-    try {
-      reader = new BufferedReader(new FileReader(restoreFile));
+    try (BufferedReader reader = new BufferedReader(new FileReader(restoreFile))) {
       parseRestoreFile(reader);
-    } finally {
-      if (null != reader) {
-        reader.close();
-      }
     }
   }
 
   /**
-   * Searches for the incremental backup marker.
+   * Searches for the incremental backup marker and parses the incremental portion.
    * 
    * @param reader restore file reader.
-   * @throws IOException
    */
-  private void parseRestoreFile(BufferedReader reader) throws IOException {
+  private void parseRestoreFile(final BufferedReader reader) throws IOException {
     boolean markerFound = false;
-    String line = null;
-    String incrementalMarker = getIncrementalMarker();
 
+    String line = null;
     while (!markerFound && (null != (line = reader.readLine()))) {
-      markerFound = line.startsWith(incrementalMarker);
+      markerFound = line.contains(RestoreScript.INCREMENTAL_MARKER_COMMENT);
     }
 
     if (markerFound) {
@@ -113,13 +105,6 @@ public abstract class BackupInspector {
   }
 
   /**
-   * @return true if the host operating system is windows.
-   */
-  public static boolean isWindows() {
-    return (System.getProperty("os.name").indexOf("Windows") != -1);
-  }
-
-  /**
    * Returns true if the restore script is incremental.
    */
   public boolean isIncremental() {
@@ -138,7 +123,7 @@ public abstract class BackupInspector {
    * 
    * @param oplogFileName an operation log file.
    */
-  public String getScriptLineForOplogFile(String oplogFileName) {
+  public String getScriptLineForOplogFile(final String oplogFileName) {
     return this.oplogLineMap.get(oplogFileName);
   }
 
@@ -151,11 +136,6 @@ public abstract class BackupInspector {
   }
 
   /**
-   * @return the incremental marke contained in the backup restore script.
-   */
-  protected abstract String getIncrementalMarker();
-
-  /**
    * Returns the restore script for the backup.
    * 
    * @param backupDir a member's backup directory.
@@ -167,180 +147,19 @@ public abstract class BackupInspector {
    * 
    * @param oplogFileName an operation log file.
    */
-  public abstract String getCopyToForOplogFile(String oplogFileName);
+  public abstract String getCopyToForOplogFile(final String oplogFileName);
 
   /**
    * Returns the copy from operation log file path for an operation log file name.
    * 
    * @param oplogFileName an operation log file.
    */
-  public abstract String getCopyFromForOplogFile(String oplogFileName);
-
-  /**
-   * Parses out operation log data from the incremental backup portion of the restore script.
-   * 
-   * @param reader restore file reader.
-   * @throws IOException
-   */
-  protected abstract void parseOplogLines(BufferedReader reader) throws IOException;
-}
-
-
-/**
- * A BackupInspector for the Windows platform(s).
- *
- */
-class WindowsBackupInspector extends BackupInspector {
-  /**
-   * When found indicates that the restore script was produced from an incremental backup.
-   */
-  private static final String INCREMENTAL_MARKER = "rem Incremental backup";
-
-  /**
-   * Restore file for windows platform.
-   */
-  static final String RESTORE_FILE = "restore.bat";
-
-  WindowsBackupInspector(File backupDir) throws IOException {
-    super(backupDir);
-  }
-
-  @Override
-  public String getCopyFromForOplogFile(String oplogFileName) {
-    String copyFrom = null;
-    String line = this.oplogLineMap.get(oplogFileName);
-
-    if (null != line) {
-      String[] parts = line.split("\\s");
-      copyFrom = parts[1].substring(1, parts[1].length() - 1) + File.separator + parts[3];
-    }
-
-    return copyFrom;
-  }
-
-  @Override
-  public String getCopyToForOplogFile(String oplogFileName) {
-    String copyTo = null;
-    String line = this.oplogLineMap.get(oplogFileName);
-
-    if (null != line) {
-      String[] parts = line.split("\\s");
-      copyTo = parts[2].substring(1, parts[2].length() - 1) + File.separator + parts[3];
-    }
-
-    return copyTo;
-  }
-
-  @Override
-  /**
-   * Parses out operation log data from the incremental backup portion of the restore script.
-   * 
-   * @param reader restore file reader.
-   * @throws IOException
-   */
-  protected void parseOplogLines(BufferedReader reader) throws IOException {
-    String line = null;
-
-    int beginIndex, endIndex;
-    String oplogName = "";
-    while (null != (line = reader.readLine())) {
-
-      if (line.startsWith("robocopy")) {
-        beginIndex = line.lastIndexOf("\"") + 2;
-        endIndex = line.indexOf("/njh", beginIndex) - 1;
-        oplogName = line.substring(beginIndex, endIndex);
-        this.oplogFileNames.add(oplogName);
-        this.oplogLineMap.put(oplogName, line);
-      } else if (line.startsWith("IF")) {
-        continue;
-      } else if (line.contains(RestoreScript.EXIT_MARKER)) {
-        break;
-      }
-    }
-  }
+  public abstract String getCopyFromForOplogFile(final String oplogFileName);
 
-  @Override
-  protected String getIncrementalMarker() {
-    return INCREMENTAL_MARKER;
-  }
-
-  @Override
-  protected File getRestoreFile(final File backupDir) {
-    return new File(backupDir, RESTORE_FILE);
-  }
-}
-
-
-/**
- * A BackupInspector for Unix platforms.
- */
-class UnixBackupInspector extends BackupInspector {
-  /**
-   * When found indicates that the restore script was produced from an incremental backup.
-   */
-  private static final String INCREMENTAL_MARKER = "#Incremental backup";
-
-  /**
-   * Restore file for windows platform.
-   */
-  static final String RESTORE_FILE = "restore.sh";
-
-  UnixBackupInspector(File backupDir) throws IOException {
-    super(backupDir);
-  }
-
-  @Override
-  public String getCopyFromForOplogFile(String oplogFileName) {
-    String copyFrom = null;
-    String line = this.oplogLineMap.get(oplogFileName);
-
-    if (null != line) {
-      String[] parts = line.split("\\s");
-      copyFrom = parts[2].substring(1, parts[2].length() - 1);
-    }
-
-    return copyFrom;
-  }
-
-  @Override
-  public String getCopyToForOplogFile(String oplogFileName) {
-    String copyTo = null;
-    String line = this.oplogLineMap.get(oplogFileName);
-
-    if (null != line) {
-      String[] parts = line.split("\\s");
-      copyTo = parts[3].substring(1, parts[3].length() - 1);
-    }
-
-    return copyTo;
-  }
-
-  @Override
   /**
    * Parses out operation log data from the incremental backup portion of the restore script.
    * 
    * @param reader restore file reader.
-   * @throws IOException
    */
-  protected void parseOplogLines(BufferedReader reader) throws IOException {
-    String line = null;
-
-    while (null != (line = reader.readLine())) {
-      int beginIndex = line.lastIndexOf(File.separator) + 1;
-      int endIndex = line.length() - 1;
-      String oplogName = line.substring(beginIndex, endIndex);
-      this.oplogFileNames.add(oplogName);
-      this.oplogLineMap.put(oplogName, line);
-    }
-  }
-
-  @Override
-  protected String getIncrementalMarker() {
-    return INCREMENTAL_MARKER;
-  }
-
-  @Override
-  protected File getRestoreFile(final File backupDir) {
-    return new File(backupDir, RESTORE_FILE);
-  }
+  protected abstract void parseOplogLines(final BufferedReader reader) throws IOException;
 }
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/RestoreScript.java b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/RestoreScript.java
index b23bce6..f16651c 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/RestoreScript.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/RestoreScript.java
@@ -23,209 +23,131 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.geode.internal.lang.SystemUtils;
+
 /**
  * This class is used to automatically generate a restore script for a backup. It keeps a list of
  * files that were backed up, and a list of files that we should test for to avoid overriding when
  * we restore the backup.
  * 
+ * <p>
  * It generates either a restore.sh for unix or a restore.bat for windows.
- * 
- *
  */
 public class RestoreScript {
-  public static final String EXIT_MARKER = "Exit Functions";
 
-  private static final ScriptGenerator UNIX_GENERATOR = new UnixScriptGenerator();
-  private static final ScriptGenerator WINDOWS_GENERATOR = new WindowsScriptGenerator();
+  static final String INCREMENTAL_MARKER_COMMENT =
+      "Incremental backup.  Restore baseline originals from previous backups.";
+
+  static final String REFUSE_TO_OVERWRITE_MESSAGE = "Backup not restored. Refusing to overwrite ";
+
+  private static final String[] ABOUT_SCRIPT_COMMENT =
+      {"Restore a backup of gemfire persistent data to the location it was backed up",
+          "from. This script will refuse to restore if the original data still exists.",
+          "This script was automatically generated by the gemfire backup utility.",};
+
+  private static final String EXISTENCE_CHECK_COMMENT =
+      "Test for existing originals.  If they exist, do not restore the backup.";
+
+  private static final String RESTORE_DATA_COMMENT = "Restore data";
 
-  private Map<File, File> baselineFiles = new HashMap<File, File>();
+  private final ScriptGenerator generator;
+  private final Map<File, File> baselineFiles = new HashMap<File, File>();
   private final Map<File, File> backedUpFiles = new LinkedHashMap<File, File>();
   private final List<File> existenceTests = new ArrayList<File>();
 
-  public void addBaselineFiles(Map<File, File> baselineFiles) {
-    this.baselineFiles.putAll(baselineFiles);
-  }
+  private PrintWriter writer;
+  private File outputDir;
 
-  public void addFile(File originalFile, File backupFile) {
-    backedUpFiles.put(backupFile, originalFile.getAbsoluteFile());
+  public RestoreScript() {
+    this(SystemUtils.isWindows() ? new WindowsScriptGenerator() : new UnixScriptGenerator());
   }
 
-  public void addExistenceTest(File originalFile) {
-    existenceTests.add(originalFile.getAbsoluteFile());
+  RestoreScript(final ScriptGenerator generator) {
+    this.generator = generator;
   }
 
-  public void generate(File outputDir) throws FileNotFoundException {
-    if (isWindows()) {
-      generateWindowsScript(outputDir);
-    } else {
-      generateUnixScript(outputDir);
-    }
+  public void addBaselineFiles(final Map<File, File> baselineFiles) {
+    this.baselineFiles.putAll(baselineFiles);
+  }
 
+  public void addFile(final File originalFile, final File backupFile) {
+    backedUpFiles.put(backupFile, originalFile.getAbsoluteFile());
   }
 
-  private void generateWindowsScript(File outputDir) throws FileNotFoundException {
-    File outputFile = new File(outputDir, "restore.bat");
-    generateScript(outputDir, outputFile, WINDOWS_GENERATOR);
+  public void addExistenceTest(final File originalFile) {
+    existenceTests.add(originalFile.getAbsoluteFile());
   }
 
-  private void generateUnixScript(File outputDir) throws FileNotFoundException {
-    File outputFile = new File(outputDir, "restore.sh");
-    generateScript(outputDir, outputFile, UNIX_GENERATOR);
+  public void generate(final File outputDir) throws FileNotFoundException {
+    this.outputDir = outputDir;
+    File outputFile = new File(outputDir, generator.getScriptName());
+    generateScript(outputFile);
   }
 
-  private void generateScript(File outputDir, File outputFile, ScriptGenerator osGenerator)
-      throws FileNotFoundException {
-    PrintWriter writer = new PrintWriter(outputFile);
+  private void generateScript(final File outputFile) throws FileNotFoundException {
+    writer = new PrintWriter(outputFile);
     try {
-      osGenerator.writePreamble(writer);
-      writer.println();
-      osGenerator.writeComment(writer,
-          "Restore a backup of gemfire persistent data to the location it was backed up");
-      osGenerator.writeComment(writer, "from.");
-      osGenerator.writeComment(writer,
-          "This script will refuse to restore if the original data still exists.");
-      writer.println();
-      osGenerator.writeComment(writer,
-          "This script was automatically generated by the gemfire backup utility.");
-      writer.println();
-      osGenerator.writeComment(writer,
-          "Test for existing originals. If they exist, do not restore the backup.");
-      for (File file : existenceTests) {
-        osGenerator.writeExistenceTest(writer, file);
-      }
-      writer.println();
-      osGenerator.writeComment(writer, "Restore data");
-      for (Map.Entry<File, File> entry : backedUpFiles.entrySet()) {
-        File backup = entry.getKey();
-        boolean backupHasFiles = backup.isDirectory() && backup.list().length != 0;
-        backup = outputDir.toPath().relativize(backup.toPath()).toFile();
-        File original = entry.getValue();
-        if (original.isDirectory()) {
-          osGenerator.writeCopyDirectoryContents(writer, backup, original, backupHasFiles);
-        } else {
-          osGenerator.writeCopyFile(writer, backup, original);
-        }
-      }
-
-      // Write out baseline file copies in restore script (if there are any) if this is a restore
-      // for an incremental backup
-      if (!this.baselineFiles.isEmpty()) {
-        writer.println();
-        osGenerator.writeComment(writer,
-            "Incremental backup.  Restore baseline originals from previous backups.");
-        for (Map.Entry<File, File> entry : this.baselineFiles.entrySet()) {
-          osGenerator.writeCopyFile(writer, entry.getKey(), entry.getValue());
-        }
-      }
 
-      if (isWindows()) {
-        osGenerator.writeExit(writer);
-      }
+      writePreamble();
+      writeAbout();
+      writeExistenceTest();
+      writeRestoreData();
+      writeIncrementalData();
+      generator.writeExit(writer);
 
     } finally {
       writer.close();
     }
+
     outputFile.setExecutable(true, true);
   }
 
-  // TODO prpersist - We've got this code replicated
-  // in 10 different places in our product. Maybe we
-  // need to put this method somewhere :)
-  private boolean isWindows() {
-    String os = System.getProperty("os.name");
-    if (os != null) {
-      if (os.contains("Windows")) {
-        return true;
-      }
-    }
-    return false;
+  private void writePreamble() {
+    generator.writePreamble(writer);
+    writer.println();
   }
 
-  private static interface ScriptGenerator {
-
-    void writePreamble(PrintWriter writer);
-
-    void writeExit(PrintWriter writer);
-
-    void writeCopyFile(PrintWriter writer, File backup, File original);
-
-    void writeCopyDirectoryContents(PrintWriter writer, File backup, File original,
-        boolean backupHasFiles);
-
-    void writeExistenceTest(PrintWriter writer, File file);
-
-    void writeComment(PrintWriter writer, String string);
-
-  };
-
-  private static class WindowsScriptGenerator implements ScriptGenerator {
-    final String ERROR_CHECK = "IF %ERRORLEVEL% GEQ 4 GOTO Exit_Bad";
-
-    public void writePreamble(PrintWriter writer) {
-      writer.println("echo off");
-      writer.println("cd %~dp0");
-    }
-
-    public void writeComment(PrintWriter writer, String string) {
-      writer.println("rem " + string);
-    }
-
-    public void writeCopyDirectoryContents(PrintWriter writer, File backup, File original,
-        boolean backupHasFiles) {
-      writer.println("mkdir \"" + original + "\"");
-      writer.println("C:\\Windows\\System32\\Robocopy.exe \"" + backup + "\" \"" + original
-          + "\" /e /njh /njs");
-      writer.println(ERROR_CHECK);
-    }
-
-    public void writeCopyFile(PrintWriter writer, File source, File destination) {
-      String fileName = source.getName();
-      String sourcePath = source.getParent() == null ? "." : source.getParent();
-      String destinationPath = destination.getParent() == null ? "." : destination.getParent();
-      writer.println("C:\\Windows\\System32\\Robocopy.exe \"" + sourcePath + "\" \""
-          + destinationPath + "\" " + fileName + " /njh /njs");
-      writer.println(ERROR_CHECK);
-    }
-
-    public void writeExistenceTest(PrintWriter writer, File file) {
-      writer.println("IF EXIST \"" + file + "\" echo \"Backup not restored. Refusing to overwrite "
-          + file + "\" && exit /B 1 ");
-    }
-
-    public void writeExit(PrintWriter writer) {
-      writeComment(writer, EXIT_MARKER);
-      writer.println(":Exit_Good\nexit /B 0\n\n:Exit_Bad\nexit /B 1");
+  private void writeAbout() {
+    for (String comment : ABOUT_SCRIPT_COMMENT) {
+      generator.writeComment(writer, comment);
     }
+    writer.println();
   }
 
-  private static class UnixScriptGenerator implements ScriptGenerator {
-    public void writePreamble(PrintWriter writer) {
-      writer.println("#!/bin/bash -e");
-      writer.println("cd `dirname $0`");
-    }
-
-    public void writeComment(PrintWriter writer, String string) {
-      writer.println("#" + string);
+  private void writeExistenceTest() {
+    generator.writeComment(writer, EXISTENCE_CHECK_COMMENT);
+    for (File file : existenceTests) {
+      generator.writeExistenceTest(writer, file);
     }
+    writer.println();
+  }
 
-    public void writeCopyDirectoryContents(PrintWriter writer, File backup, File original,
-        boolean backupHasFiles) {
-      writer.println("mkdir -p '" + original + "'");
-      if (backupHasFiles) {
-        writer.println("cp -rp '" + backup + "'/* '" + original + "'");
+  private void writeRestoreData() {
+    generator.writeComment(writer, RESTORE_DATA_COMMENT);
+    for (Map.Entry<File, File> entry : backedUpFiles.entrySet()) {
+      File backup = entry.getKey();
+      boolean backupHasFiles = backup.isDirectory() && backup.list().length != 0;
+      backup = outputDir.toPath().relativize(backup.toPath()).toFile();
+      File original = entry.getValue();
+      if (original.isDirectory()) {
+        generator.writeCopyDirectoryContents(writer, backup, original, backupHasFiles);
+      } else {
+        generator.writeCopyFile(writer, backup, original);
       }
     }
+  }
 
-    public void writeCopyFile(PrintWriter writer, File backup, File original) {
-      writer.println("cp -p '" + backup + "' '" + original + "'");
+  private void writeIncrementalData() {
+    // Write out baseline file copies in restore script (if there are any) if this is a restore
+    // for an incremental backup
+    if (this.baselineFiles.isEmpty()) {
+      return;
     }
 
-    public void writeExistenceTest(PrintWriter writer, File file) {
-      writer.println("test -e '" + file + "' && echo 'Backup not restored. Refusing to overwrite "
-          + file + "' && exit 1 ");
+    writer.println();
+    generator.writeComment(writer, INCREMENTAL_MARKER_COMMENT);
+    for (Map.Entry<File, File> entry : this.baselineFiles.entrySet()) {
+      generator.writeCopyFile(writer, entry.getKey(), entry.getValue());
     }
-
-    public void writeExit(PrintWriter writer) {}
   }
-
 }
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/ScriptGenerator.java b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/ScriptGenerator.java
new file mode 100644
index 0000000..59c2d3b
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/ScriptGenerator.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.persistence;
+
+import java.io.File;
+import java.io.PrintWriter;
+
+interface ScriptGenerator {
+
+  void writePreamble(PrintWriter writer);
+
+  void writeExit(PrintWriter writer);
+
+  void writeCopyFile(PrintWriter writer, File backup, File original);
+
+  void writeCopyDirectoryContents(PrintWriter writer, File backup, File original,
+      boolean backupHasFiles);
+
+  void writeExistenceTest(PrintWriter writer, File file);
+
+  void writeComment(PrintWriter writer, String string);
+
+  String getScriptName();
+
+}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/UnixBackupInspector.java b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/UnixBackupInspector.java
new file mode 100644
index 0000000..b53722e
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/UnixBackupInspector.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.persistence;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * A BackupInspector for Unix platforms.
+ */
+class UnixBackupInspector extends BackupInspector {
+
+  /**
+   * Restore file for windows platform.
+   */
+  private static final String RESTORE_FILE = "restore.sh";
+
+  UnixBackupInspector(final File backupDir) throws IOException {
+    super(backupDir);
+  }
+
+  @Override
+  public String getCopyFromForOplogFile(final String oplogFileName) {
+    String copyFrom = null;
+    String line = this.oplogLineMap.get(oplogFileName);
+
+    if (null != line) {
+      String[] parts = line.split("\\s");
+      copyFrom = parts[2].substring(1, parts[2].length() - 1);
+    }
+
+    return copyFrom;
+  }
+
+  @Override
+  public String getCopyToForOplogFile(final String oplogFileName) {
+    String copyTo = null;
+    String line = this.oplogLineMap.get(oplogFileName);
+
+    if (null != line) {
+      String[] parts = line.split("\\s");
+      copyTo = parts[3].substring(1, parts[3].length() - 1);
+    }
+
+    return copyTo;
+  }
+
+  @Override
+  protected void parseOplogLines(final BufferedReader reader) throws IOException {
+    String line = null;
+
+    while (null != (line = reader.readLine())) {
+      int beginIndex = line.lastIndexOf(File.separator) + 1;
+      int endIndex = line.length() - 1;
+      String oplogName = line.substring(beginIndex, endIndex);
+      this.oplogFileNames.add(oplogName);
+      this.oplogLineMap.put(oplogName, line);
+    }
+  }
+
+  @Override
+  protected File getRestoreFile(final File backupDir) {
+    return new File(backupDir, RESTORE_FILE);
+  }
+}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/UnixScriptGenerator.java b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/UnixScriptGenerator.java
new file mode 100644
index 0000000..cddd09e
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/UnixScriptGenerator.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.persistence;
+
+import java.io.File;
+import java.io.PrintWriter;
+
+class UnixScriptGenerator implements ScriptGenerator {
+
+  static final String SCRIPT_FILE_NAME = "restore.sh";
+
+  public void writePreamble(PrintWriter writer) {
+    writer.println("#!/bin/bash -e");
+    writer.println("cd `dirname $0`");
+  }
+
+  public void writeComment(PrintWriter writer, String string) {
+    writer.println("# " + string);
+  }
+
+  public void writeCopyDirectoryContents(PrintWriter writer, File backup, File original,
+      boolean backupHasFiles) {
+    writer.println("mkdir -p '" + original + "'");
+    if (backupHasFiles) {
+      writer.println("cp -rp '" + backup + "'/* '" + original + "'");
+    }
+  }
+
+  public void writeCopyFile(PrintWriter writer, File backup, File original) {
+    writer.println("cp -p '" + backup + "' '" + original + "'");
+  }
+
+  public void writeExistenceTest(PrintWriter writer, File file) {
+    writer.println("test -e '" + file + "' && echo '" + RestoreScript.REFUSE_TO_OVERWRITE_MESSAGE
+        + file + "' && exit 1 ");
+  }
+
+  public void writeExit(PrintWriter writer) {
+    // do nothing
+  }
+
+  @Override
+  public String getScriptName() {
+    return SCRIPT_FILE_NAME;
+  }
+}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/WindowsBackupInspector.java b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/WindowsBackupInspector.java
new file mode 100644
index 0000000..c5adea8
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/WindowsBackupInspector.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.persistence;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * A BackupInspector for the Windows platform(s).
+ */
+class WindowsBackupInspector extends BackupInspector {
+
+  /**
+   * Restore file for windows platform.
+   */
+  private static final String RESTORE_FILE = "restore.bat";
+
+  WindowsBackupInspector(final File backupDir) throws IOException {
+    super(backupDir);
+  }
+
+  @Override
+  public String getCopyFromForOplogFile(final String oplogFileName) {
+    String copyFrom = null;
+    String line = this.oplogLineMap.get(oplogFileName);
+
+    if (null != line) {
+      String[] parts = line.split("\\s");
+      copyFrom = parts[1].substring(1, parts[1].length() - 1) + File.separator + parts[3];
+    }
+
+    return copyFrom;
+  }
+
+  @Override
+  public String getCopyToForOplogFile(final String oplogFileName) {
+    String copyTo = null;
+    String line = this.oplogLineMap.get(oplogFileName);
+
+    if (null != line) {
+      String[] parts = line.split("\\s");
+      copyTo = parts[2].substring(1, parts[2].length() - 1) + File.separator + parts[3];
+    }
+
+    return copyTo;
+  }
+
+  @Override
+  protected void parseOplogLines(final BufferedReader reader) throws IOException {
+    String line = null;
+
+    int beginIndex, endIndex;
+    String oplogName = "";
+    while (null != (line = reader.readLine())) {
+      if (line.startsWith("IF")) {
+        continue;
+      } else if (line.contains(WindowsScriptGenerator.EXIT_MARKER)) {
+        break;
+      } else {
+        beginIndex = line.lastIndexOf("\"") + 1;
+        endIndex = line.indexOf(WindowsScriptGenerator.ROBOCOPY_NO_JOB_HEADER, beginIndex) - 1;
+        oplogName = (line.substring(beginIndex, endIndex)).trim();
+        this.oplogFileNames.add(oplogName);
+        this.oplogLineMap.put(oplogName, line);
+      }
+    }
+  }
+
+  @Override
+  protected File getRestoreFile(final File backupDir) {
+    return new File(backupDir, RESTORE_FILE);
+  }
+}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/WindowsScriptGenerator.java b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/WindowsScriptGenerator.java
new file mode 100644
index 0000000..2917ea3
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/WindowsScriptGenerator.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.persistence;
+
+import java.io.File;
+import java.io.PrintWriter;
+
+class WindowsScriptGenerator implements ScriptGenerator {
+
+  static final String ERROR_CHECK = "IF %ERRORLEVEL% GEQ 4 GOTO Exit_Bad";
+  static final String ROBOCOPY_COMMAND = "Robocopy.exe";
+  static final String ROBOCOPY_NO_JOB_HEADER = "/njh";
+  static final String ROBOCOPY_NO_JOB_SUMMARY = "/njs";
+  static final String ROBOCOPY_COPY_SUBDIRS = "/e";
+  static final String EXIT_MARKER = "Exit Functions";
+  static final String SCRIPT_FILE_NAME = "restore.bat";
+
+  @Override
+  public void writePreamble(PrintWriter writer) {
+    writer.println("echo off");
+    writer.println("cd %~dp0");
+  }
+
+  @Override
+  public void writeComment(PrintWriter writer, String string) {
+    writer.println("rem " + string);
+  }
+
+  @Override
+  public void writeCopyDirectoryContents(PrintWriter writer, File backup, File original,
+      boolean backupHasFiles) {
+    writer.println("mkdir \"" + original + "\"");
+    writer.println(ROBOCOPY_COMMAND + " \"" + backup + "\" \"" + original + "\" "
+        + ROBOCOPY_COPY_SUBDIRS + " " + ROBOCOPY_NO_JOB_HEADER + " " + ROBOCOPY_NO_JOB_SUMMARY);
+    writer.println(ERROR_CHECK);
+  }
+
+  @Override
+  public void writeCopyFile(PrintWriter writer, File source, File destination) {
+    String fileName = source.getName();
+    String sourcePath = source.getParent() == null ? "." : source.getParent();
+    String destinationPath = destination.getParent() == null ? "." : destination.getParent();
+    writer.println(ROBOCOPY_COMMAND + " \"" + sourcePath + "\" \"" + destinationPath + "\" "
+        + fileName + " " + ROBOCOPY_NO_JOB_HEADER + " " + ROBOCOPY_NO_JOB_SUMMARY);
+    writer.println(ERROR_CHECK);
+  }
+
+  @Override
+  public void writeExistenceTest(PrintWriter writer, File file) {
+    writer.println("IF EXIST \"" + file + "\" echo \"" + RestoreScript.REFUSE_TO_OVERWRITE_MESSAGE
+        + file + "\" && exit /B 1 ");
+  }
+
+  @Override
+  public void writeExit(PrintWriter writer) {
+    writeComment(writer, WindowsScriptGenerator.EXIT_MARKER);
+    writer.println(":Exit_Good\nexit /B 0\n\n:Exit_Bad\nexit /B 1");
+  }
+
+  @Override
+  public String getScriptName() {
+    return SCRIPT_FILE_NAME;
+  }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/persistence/BackupInspectorIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/persistence/BackupInspectorIntegrationTest.java
new file mode 100644
index 0000000..8cc1f47
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/persistence/BackupInspectorIntegrationTest.java
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.persistence;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ * Tests for the BackupInspector.
+ */
+@Category(IntegrationTest.class)
+public class BackupInspectorIntegrationTest {
+
+  private static final String IF_FILE_SUFFIX = ".if";
+  private static final String CRF_FILE_SUFFIX = ".crf";
+  private static final String DRF_FILE_SUFFIX = ".drf";
+
+  private static final String DISK_STORE_BASE_FILE_NAME = "diskStore";
+  private static final String DISK_STORE_INCREMENTAL_BASE_FILE_NAME = "diskStore_1";
+
+  private static final String IF_FILE_NAME = DISK_STORE_BASE_FILE_NAME + IF_FILE_SUFFIX;
+  private static final String CRF_FILE_NAME = DISK_STORE_BASE_FILE_NAME + CRF_FILE_SUFFIX;
+  private static final String DRF_FILE_NAME = DISK_STORE_BASE_FILE_NAME + DRF_FILE_SUFFIX;
+
+  private static final String DISK_STORE_DIR_NAME = "diskStore";
+  private static final String BACKUP_DIR_NAME = "backup";
+  private static final String INCREMENTAL_DIR_NAME = "incremental";
+
+  // directories created during the test
+  private File diskDir = null;
+  private File fullBackupDir = null;
+  private File incrementalBackupDir = null;
+
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  /**
+   * Set up data for all tests.
+   */
+  @Before
+  public void setUp() throws Exception {
+    diskDir = createFakeDir(DISK_STORE_DIR_NAME, DISK_STORE_BASE_FILE_NAME);
+    fullBackupDir = createFakeDir(BACKUP_DIR_NAME, DISK_STORE_BASE_FILE_NAME);
+    incrementalBackupDir =
+        createFakeDir(INCREMENTAL_DIR_NAME, DISK_STORE_INCREMENTAL_BASE_FILE_NAME);
+    createRestoreScript(fullBackupDir, null); // full restore script; no incremental
+    createRestoreScript(incrementalBackupDir, fullBackupDir); // incremental restore script
+  }
+
+  /**
+   * Create a directory containing empty oplog files.
+   * 
+   * @param dirName The name of the directory to create.
+   * @param diskFileBaseName The base name of the oplog files created in the new directory.
+   */
+  private File createFakeDir(String dirName, String diskFileBaseName) throws IOException {
+    File aDir = temporaryFolder.newFolder(dirName);
+    new File(aDir, diskFileBaseName + IF_FILE_SUFFIX).createNewFile();
+    new File(aDir, diskFileBaseName + CRF_FILE_SUFFIX).createNewFile();
+    new File(aDir, diskFileBaseName + DRF_FILE_SUFFIX).createNewFile();
+    return aDir;
+  }
+
+  /**
+   * Create a restore script. Place it in backupDirToRestoreFrom.
+   * 
+   * @param backupDirToRestoreFrom The directory containing the backup files to restore from. This
+   *        could be a full backup or an incremental backup.
+   * @param incrementalBaseDir If backupdirToRestoreFrom is an incremental backup, this directory
+   *        contains the full backup to apply the incremental to.
+   */
+  private void createRestoreScript(File backupDirToRestoreFrom, File incrementalBaseDir)
+      throws IOException {
+    RestoreScript restoreScript = new RestoreScript();
+    restoreScript.addExistenceTest(new File(diskDir, IF_FILE_NAME));
+    restoreScript.addFile(diskDir, backupDirToRestoreFrom);
+    if (incrementalBaseDir != null) {
+      Map<File, File> baselineFilesMap = new HashMap<File, File>();
+      baselineFilesMap.put(new File(incrementalBaseDir, CRF_FILE_NAME),
+          new File(diskDir, CRF_FILE_NAME));
+      baselineFilesMap.put(new File(incrementalBaseDir, DRF_FILE_NAME),
+          new File(diskDir, DRF_FILE_NAME));
+      restoreScript.addBaselineFiles(baselineFilesMap);
+    }
+    restoreScript.generate(backupDirToRestoreFrom);
+  }
+  
+  /**
+   * Tests that an IOException is thrown for a non-existent restore script.
+   */
+  @Test
+  public void testNonExistentScriptFile() throws Exception {
+    assertThatThrownBy(
+        () -> BackupInspector.createInspector(temporaryFolder.newFolder("emptyFolder")))
+            .isInstanceOf(IOException.class)
+            .hasMessageMatching("Restore file restore\\.(bat|sh) does not exist.");
+  }
+
+  /**
+   * Tests copy lines for an incremental backup.
+   * 
+   * @param inspector a BackupInspector.
+   */
+  private void testIncrementalBackupScript(BackupInspector inspector) throws Exception {
+    // verify copyFrom
+    assertThat(inspector.getCopyFromForOplogFile(CRF_FILE_NAME))
+        .isEqualTo(fullBackupDir.getAbsolutePath() + File.separator + CRF_FILE_NAME);
+    assertThat(inspector.getCopyFromForOplogFile(DRF_FILE_NAME))
+        .isEqualTo(fullBackupDir.getAbsolutePath() + File.separator + DRF_FILE_NAME);
+
+    // verify copyTo
+    assertThat(inspector.getCopyToForOplogFile(CRF_FILE_NAME))
+        .isEqualTo(diskDir.getAbsolutePath() + File.separator + CRF_FILE_NAME);
+    assertThat(inspector.getCopyToForOplogFile(DRF_FILE_NAME))
+        .isEqualTo(diskDir.getAbsolutePath() + File.separator + DRF_FILE_NAME);
+  }
+
+  /**
+   * Tests that the parser succeeds for an incremental backup restore script.s
+   */
+  @Test
+  public void testIncrementalBackupScript() throws Exception {
+    BackupInspector inspector = BackupInspector.createInspector(incrementalBackupDir);
+    assertThat(inspector.isIncremental()).isTrue();
+    Set<String> oplogFiles = inspector.getIncrementalOplogFileNames();
+    assertThat(oplogFiles.isEmpty()).isFalse();
+    assertThat(oplogFiles).hasSize(2);
+    assertThat(oplogFiles.contains(CRF_FILE_NAME)).isTrue();
+    assertThat(oplogFiles.contains(DRF_FILE_NAME)).isTrue();
+    testIncrementalBackupScript(inspector);
+  }
+
+  /**
+   * Tests that the parser works with a full backup restore script.
+   */
+  @Test
+  public void testFullBackupScript() throws Exception {
+    BackupInspector inspector = BackupInspector.createInspector(fullBackupDir);
+    assertThat(inspector.isIncremental()).isFalse();
+    assertThat(inspector.getIncrementalOplogFileNames().isEmpty()).isTrue();
+    assertThat(inspector.getScriptLineForOplogFile(DRF_FILE_NAME)).isNull();
+  }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/persistence/BackupInspectorJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/persistence/BackupInspectorJUnitTest.java
deleted file mode 100644
index 5fd3585..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/persistence/BackupInspectorJUnitTest.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.internal.cache.persistence;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.geode.test.junit.categories.IntegrationTest;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Set;
-
-/**
- * TODO: fails when running integrationTest from gradle command-line on Windows 7
- *
- * Tests for the BackupInspector.
- */
-@Category(IntegrationTest.class)
-public class BackupInspectorJUnitTest {
-
-  private static final String UNIX_INCREMENTAL_BACKUP_SCRIPT =
-      "#!/bin/bash -e\ncd `dirname $0`\n\n#Restore a backup of gemfire persistent data to the location it was backed up\n#from.\n#This script will refuse to restore if the original data still exists.\n\n#This script was automatically generated by the gemfire backup utility.\n\n#Test for existing originals. If they exist, do not restore the backup.\ntest -e '/Users/rholmes/Projects/gemfire/test/cacheserver/disk3/BACKUPbar.if' && echo 'Backup not restored. Refusing to overwrite /Users/rhol [...]
-  private static final String UNIX_FULL_BACKUP_SCRIPT =
-      "#!/bin/bash -e\ncd `dirname $0`\n\n#Restore a backup of gemfire persistent data to the location it was backed up\n#from.\n#This script will refuse to restore if the original data still exists.\n\n#This script was automatically generated by the gemfire backup utility.\n\n#Test for existing originals. If they exist, do not restore the backup.\ntest -e '/Users/rholmes/Projects/gemfire/test/cacheserver/disk3/BACKUPbar.if' && echo 'Backup not restored. Refusing to overwrite /Users/rhol [...]
-
-  private static final String WINDOWS_INCREMENTAL_BACKUP_SCRIPT =
-      "rem echo off\n\nrem Restore a backup of gemfire persistent data to the location it was backed up\nrem from.\nrem This script will refuse to restore if the original data still exists.\n\nrem This script was automatically generated by the gemfire backup utility.\n\nrem Test for existing originals. If they exist, do not restore the backup.\nIF EXIST \"\\Users\\rholmes\\Projects\\gemfire\\test\\cacheserver\\disk3\\BACKUPbar.if\" echo \"Backup not restored. Refusing to overwrite \\User [...]
-  private static final String WINDOWS_FULL_BACKUP_SCRIPT =
-      "rem echo off\n\nrem Restore a backup of gemfire persistent data to the location it was backed up\nrem from.\nrem This script will refuse to restore if the original data still exists.\n\nrem This script was automatically generated by the gemfire backup utility.\n\nrem Test for existing originals. If they exist, do not restore the backup.\nIF EXIST \"\\Users\\rholmes\\Projects\\gemfire\\test\\cacheserver\\disk3\\BACKUPbar.if\" echo \"Backup not restored. Refusing to overwrite \\User [...]
-
-  private static final String OPLOG_FILENAME_1 = "BACKUPbar_1.drf";
-  private static final String OPLOG_FILENAME_2 = "BACKUPfoo_1.crf";
-  private static final String OPLOG_FILENAME_3 = "BACKUPfoo_1.drf";
-
-  private static final String UNIX_COPY_FROM_1 =
-      "/Users/rholmes/Projects/gemfire/test/backup/2012-05-24-09-42/rholmes_mbp_410_v1_56425/diskstores/bar/dir0/BACKUPbar_1.drf";
-  private static final String UNIX_COPY_FROM_2 =
-      "/Users/rholmes/Projects/gemfire/test/backup/2012-05-24-09-42/rholmes_mbp_410_v1_56425/diskstores/foo/dir0/BACKUPfoo_1.crf";
-  private static final String UNIX_COPY_FROM_3 =
-      "/Users/rholmes/Projects/gemfire/test/backup/2012-05-24-09-42/rholmes_mbp_410_v1_56425/diskstores/foo/dir0/BACKUPfoo_1.drf";
-
-  private static final String WINDOWS_COPY_FROM_1 =
-      "\\Users\\rholmes\\Projects\\gemfire\\test\\backup\\2012-05-24-09-42\\rholmes_mbp_410_v1_56425\\diskstores\\bar\\dir0\\BACKUPbar_1.drf";
-  private static final String WINDOWS_COPY_FROM_2 =
-      "\\Users\\rholmes\\Projects\\gemfire\\test\\backup\\2012-05-24-09-42\\rholmes_mbp_410_v1_56425\\diskstores\\foo\\dir0\\BACKUPfoo_1.crf";
-  private static final String WINDOWS_COPY_FROM_3 =
-      "\\Users\\rholmes\\Projects\\gemfire\\test\\backup\\2012-05-24-09-42\\rholmes_mbp_410_v1_56425\\diskstores\\foo\\dir0\\BACKUPfoo_1.drf";
-
-  private static final String UNIX_COPY_TO_1 =
-      "/Users/rholmes/Projects/gemfire/test/cacheserver/disk3/BACKUPbar_1.drf";
-  private static final String UNIX_COPY_TO_2 =
-      "/Users/rholmes/Projects/gemfire/test/cacheserver/disk1/BACKUPfoo_1.crf";
-  private static final String UNIX_COPY_TO_3 =
-      "/Users/rholmes/Projects/gemfire/test/cacheserver/disk1/BACKUPfoo_1.drf";
-
-  private static final String WINDOWS_COPY_TO_1 =
-      "\\Users\\rholmes\\Projects\\gemfire\\test\\cacheserver\\disk3\\BACKUPbar_1.drf";
-  private static final String WINDOWS_COPY_TO_2 =
-      "\\Users\\rholmes\\Projects\\gemfire\\test\\cacheserver\\disk1\\BACKUPfoo_1.crf";
-  private static final String WINDOWS_COPY_TO_3 =
-      "\\Users\\rholmes\\Projects\\gemfire\\test\\cacheserver\\disk1\\BACKUPfoo_1.drf";
-
-  /**
-   * Temporary incremental backup directory.
-   */
-  private File incrementalBackupDir = null;
-
-  /**
-   * Temporary full backup directory.
-   */
-  private File fullBackupDir = null;
-
-  @Rule
-  public TemporaryFolder temporaryFolder = new TemporaryFolder();
-
-  /**
-   * Set up data for all tests.
-   */
-  @Before
-  public void setUp() throws Exception {
-    File tempDir = temporaryFolder.newFolder();
-
-    /*
-     * Create an incremental backup on the file system.
-     */
-    this.incrementalBackupDir = new File(tempDir, "incremental");
-    assertTrue(this.incrementalBackupDir.mkdir());
-
-    File incrementalRestoreFile = null;
-    if (BackupInspector.isWindows()) {
-      incrementalRestoreFile =
-          new File(this.incrementalBackupDir, WindowsBackupInspector.RESTORE_FILE);
-      PrintWriter writer = new PrintWriter(incrementalRestoreFile);
-      writer.write(WINDOWS_INCREMENTAL_BACKUP_SCRIPT);
-      writer.close();
-    } else {
-      incrementalRestoreFile =
-          new File(this.incrementalBackupDir, UnixBackupInspector.RESTORE_FILE);
-      PrintWriter writer = new PrintWriter(incrementalRestoreFile);
-      writer.write(UNIX_INCREMENTAL_BACKUP_SCRIPT);
-      writer.close();
-    }
-
-    /*
-     * Create a full backup on the file system.
-     */
-    this.fullBackupDir = new File(tempDir, "backup");
-    assertTrue(this.fullBackupDir.mkdir());
-
-    File fullRestoreFile = null;
-    if (BackupInspector.isWindows()) {
-      fullRestoreFile = new File(this.fullBackupDir, WindowsBackupInspector.RESTORE_FILE);
-      PrintWriter writer = new PrintWriter(fullRestoreFile);
-      writer.write(WINDOWS_FULL_BACKUP_SCRIPT);
-      writer.close();
-    } else {
-      fullRestoreFile = new File(this.fullBackupDir, UnixBackupInspector.RESTORE_FILE);
-      PrintWriter writer = new PrintWriter(fullRestoreFile);
-      writer.write(UNIX_FULL_BACKUP_SCRIPT);
-      writer.close();
-    }
-  }
-
-  /**
-   * Tests that an IOException is thrown for a non-existent restore script.
-   */
-  @Test
-  public void testNonExistentScriptFile() throws Exception {
-    boolean ioexceptionThrown = false;
-
-    try {
-      @SuppressWarnings("unused")
-      BackupInspector inspector =
-          BackupInspector.createInspector(new File(System.getProperty("java.io.tmpdir")));
-    } catch (IOException e) {
-      ioexceptionThrown = true;
-    }
-
-    assertTrue(ioexceptionThrown);
-  }
-
-  /**
-   * Tests copy lines for windows.
-   * 
-   * @param inspector a BackupInspector.
-   */
-  private void testIncrementalBackupScriptForWindows(BackupInspector inspector) throws Exception {
-    assertEquals(WINDOWS_COPY_FROM_1, inspector.getCopyFromForOplogFile(OPLOG_FILENAME_1));
-    assertEquals(WINDOWS_COPY_TO_1, inspector.getCopyToForOplogFile(OPLOG_FILENAME_1));
-    assertEquals(WINDOWS_COPY_FROM_2, inspector.getCopyFromForOplogFile(OPLOG_FILENAME_2));
-    assertEquals(WINDOWS_COPY_TO_2, inspector.getCopyToForOplogFile(OPLOG_FILENAME_2));
-    assertEquals(WINDOWS_COPY_FROM_3, inspector.getCopyFromForOplogFile(OPLOG_FILENAME_3));
-    assertEquals(WINDOWS_COPY_TO_3, inspector.getCopyToForOplogFile(OPLOG_FILENAME_3));
-  }
-
-  /**
-   * Tests copy lines for unix.
-   * 
-   * @param inspector a BackupInspector.
-   */
-  private void testIncrementalBackupScriptForUnix(BackupInspector inspector) throws Exception {
-    assertEquals(UNIX_COPY_FROM_1, inspector.getCopyFromForOplogFile(OPLOG_FILENAME_1));
-    assertEquals(UNIX_COPY_TO_1, inspector.getCopyToForOplogFile(OPLOG_FILENAME_1));
-    assertEquals(UNIX_COPY_FROM_2, inspector.getCopyFromForOplogFile(OPLOG_FILENAME_2));
-    assertEquals(UNIX_COPY_TO_2, inspector.getCopyToForOplogFile(OPLOG_FILENAME_2));
-    assertEquals(UNIX_COPY_FROM_3, inspector.getCopyFromForOplogFile(OPLOG_FILENAME_3));
-    assertEquals(UNIX_COPY_TO_3, inspector.getCopyToForOplogFile(OPLOG_FILENAME_3));
-  }
-
-  /**
-   * Tests that the parser succeeds for an incremental backup restore script.
-   */
-  @Test
-  public void testIncrementalBackupScript() throws Exception {
-    BackupInspector inspector = BackupInspector.createInspector(incrementalBackupDir);
-
-    assertTrue(inspector.isIncremental());
-
-    Set<String> oplogFiles = inspector.getIncrementalOplogFileNames();
-
-    assertFalse(oplogFiles.isEmpty());
-    assertEquals(8, oplogFiles.size());
-    assertTrue(oplogFiles.contains(OPLOG_FILENAME_1));
-    assertTrue(oplogFiles.contains(OPLOG_FILENAME_2));
-    assertTrue(oplogFiles.contains(OPLOG_FILENAME_3));
-
-    if (BackupInspector.isWindows()) {
-      testIncrementalBackupScriptForWindows(inspector);
-    } else {
-      testIncrementalBackupScriptForUnix(inspector);
-    }
-  }
-
-  /**
-   * Tests that the parser works with a full backup restore script.
-   */
-  @Test
-  public void testFullBackupScript() throws Exception {
-    BackupInspector inspector = BackupInspector.createInspector(fullBackupDir);
-    assertFalse(inspector.isIncremental());
-    assertTrue(inspector.getIncrementalOplogFileNames().isEmpty());
-    assertNull(inspector.getScriptLineForOplogFile(OPLOG_FILENAME_1));
-  }
-}

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.