/// <summary>
/// The process for backing up a directory index is simple:
/// a) create hard links to all the files in the lucene directory in a temp director
/// that gives us the current snapshot, and protect us from lucene's
/// deleting files.
/// b) copy the hard links to the destination directory
/// c) delete the temp directory
/// </summary>
public void Execute()
{
foreach (var file in Directory.EnumerateFiles(tempPath))
{
Notify("Copying " + Path.GetFileName(file));
var fullName = new FileInfo(file).FullName;
FileCopy(file, Path.Combine(destination, Path.GetFileName(file)), fileToSize[fullName]);
Notify("Copied " + Path.GetFileName(file));
}
try
{
IOExtensions.DeleteDirectory(tempPath);
}
catch (Exception e) //cannot delete, probably because there is a file being written there
{
logger.WarnFormat(e, "Could not delete {0}, will delete those on startup", tempPath);
foreach (var file in Directory.EnumerateFiles(tempPath))
{
MoveFileEx(file, null, MoveFileDelayUntilReboot);
}
MoveFileEx(tempPath, null, MoveFileDelayUntilReboot);
}
}