Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to delete backup file when upgrading database #2432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions LiteDB/Engine/Engine/Recovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ public partial class LiteEngine
/// <summary>
/// Recovery datafile using a rebuild process. Run only on "Open" database
/// </summary>
private void Recovery(Collation collation)
private void Recovery(Collation collation, bool createBackup = true)
{
// run build service
var rebuilder = new RebuildService(_settings);
var options = new RebuildOptions
{
Collation = collation,
Password = _settings.Password,
IncludeErrorReport = true
IncludeErrorReport = true,
CreateBackup = createBackup
};

// run rebuild process
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Engine/Engine/Upgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void TryUpgrade()
}

// run rebuild process
this.Recovery(_settings.Collation);
this.Recovery(_settings.Collation, _settings.CreateBackupOnUpgrade);
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions LiteDB/Engine/EngineSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public class EngineSettings
/// </summary>
public bool Upgrade { get; set; } = false;

/// <summary>
/// If a upgrade is made a backup database is created.
/// </summary>
public bool CreateBackupOnUpgrade { get; set; } = true;

/// <summary>
/// Create new IStreamFactory for datafile
/// </summary>
Expand Down
11 changes: 9 additions & 2 deletions LiteDB/Engine/Services/RebuildService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,16 @@ public long Rebuild(RebuildOptions options)


// get difference size
return
new FileInfo(backupFilename).Length -
var diff = new FileInfo(backupFilename).Length -
new FileInfo(_settings.Filename).Length;

if (!options.CreateBackup)
{
// Delete the backup file
File.Delete(backupFilename);
}

return diff;
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions LiteDB/Engine/Structures/RebuildOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public class RebuildOptions
/// </summary>
public Collation Collation { get; set; } = null;

/// <summary>
/// Should the rebuild create a backup
/// </summary>
public bool CreateBackup { get; set; } = true;

/// <summary>
/// When set true, if any problem occurs in rebuild, a _rebuild_errors collection
/// will contains all errors found
Expand Down