Skip to content

Commit

Permalink
GEODE-6824: Copy backup files using file copy on Windows (apache#3658)
Browse files Browse the repository at this point in the history
* GEODE-6824: Copy backup files using file copy on Windows

- Typically hard links would be attempted to be used, however on
  Windows, this results in the backed up file not being deleteable.

Authored-by: Jens Deppe <[email protected]>
  • Loading branch information
jdeppe-pivotal authored and onichols-pivotal committed Jun 3, 2019
1 parent 9cdc63c commit f38fef5
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.geode.internal.cache.DiskStoreImpl;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.Oplog;
import org.apache.geode.internal.lang.SystemUtils;
import org.apache.geode.internal.logging.LogService;

class BackupFileCopier {
Expand Down Expand Up @@ -166,13 +167,20 @@ private void copyOplogFile(DiskStore diskStore, DirectoryHolder dirHolder, File
}

Path tempDiskDir = temporaryFiles.getDiskStoreDirectory(diskStore, dirHolder);
try {
createLink(tempDiskDir.resolve(file.getName()), file.toPath());
} catch (IOException e) {
logger.warn("Unable to create hard link for {}. Reverting to file copy",
tempDiskDir.toString());
if (!SystemUtils.isWindows()) {
try {
createLink(tempDiskDir.resolve(file.getName()), file.toPath());
} catch (IOException e) {
logger.warn("Unable to create hard link for {}. Reverting to file copy",
tempDiskDir.toString());
FileUtils.copyFileToDirectory(file, tempDiskDir.toFile());
}
} else {
// Hard links cannot be deleted on Windows if the process is still running, so prefer to
// actually copy the files.
FileUtils.copyFileToDirectory(file, tempDiskDir.toFile());
}

backupDefinition.addOplogFileToBackup(diskStore, tempDiskDir.resolve(file.getName()));
}

Expand Down

0 comments on commit f38fef5

Please sign in to comment.