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

Microsoft.Data.Sqlite: BackupDatabase() should yield #13834

Open
Tracked by #22949
bricelam opened this issue Apr 13, 2018 · 17 comments
Open
Tracked by #22949

Microsoft.Data.Sqlite: BackupDatabase() should yield #13834

bricelam opened this issue Apr 13, 2018 · 17 comments

Comments

@bricelam
Copy link
Contributor

Currently we call sqlite3_backup_step(backup, -1), but this will lock the database for the duration of the copy.

One of the main purposes of this API is to allow users to continue uninterrupted while a backup of the database is made.

To allow the backup to be made on a background thread while giving other threads opportunities to read, we should update it to step one page at a time and yield in between.

Unfortunately, this opens up the possibility of getting SQLITE_BUSY when stepping. This means we'll need to retry. The backup can even be automatically restarted. Which means it could take a very long time to complete. We'll need to think about timeouts and cancellation when we do this.

@bricelam bricelam changed the title SqliteConnection.BackupDatabase() should yield BackupDatabase() should yield Apr 13, 2018
@bricelam
Copy link
Contributor Author

bricelam commented Apr 13, 2018

What we currently have is useful when you want the copy done as quickly as possible. This is useful on UWP to export the database, or to save/load an in-memory database. But I don't think these scenarios would be degraded by yielding since there typically isn't concurrent access with them.

@bricelam
Copy link
Contributor Author

Triage: We decided to keep the existing method as is (no yielding), but to add additional methods/overloads for timeout, cancellation, and progress that yield.

@ajcvickers ajcvickers transferred this issue from aspnet/Microsoft.Data.Sqlite Oct 31, 2018
@ajcvickers ajcvickers added type-enhancement help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. labels Oct 31, 2018
@ajcvickers ajcvickers added this to the Backlog milestone Oct 31, 2018
@ajcvickers ajcvickers changed the title BackupDatabase() should yield Microsoft.Data.Sqlite: BackupDatabase() should yield Oct 31, 2018
@0xced
Copy link
Contributor

0xced commented Jan 25, 2019

Official SQLite documentation for reference: Using the SQLite Online Backup API.

@0xced
Copy link
Contributor

0xced commented Jan 26, 2019

I’m working on it, I hope to submit a pull request next week.

@divega divega added good first issue This issue should be relatively straightforward to fix. help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. and removed help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. good first issue This issue should be relatively straightforward to fix. labels May 31, 2019
@bricelam bricelam added the good first issue This issue should be relatively straightforward to fix. label May 31, 2019
@ajcvickers ajcvickers removed the help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. label Aug 5, 2019
@0xced
Copy link
Contributor

0xced commented Sep 18, 2019

Haha, make it next year. 🤣

@tyronx
Copy link

tyronx commented Jan 9, 2021

This would be extremely useful to have. I wrote game server software for my own game where we have very large saves. Currently its not possible to back them up efficiently while the server is running.

As a workaround I will try to run it in a separate thread for now

@MaxDZ8
Copy link

MaxDZ8 commented Oct 8, 2021

The company I work for deploys edge servers. Data is limited but so is CPU and IO performance. Our QoS make blocking unbounded operations a bit concerning.

However, I do realize the situation is particularly delicate so take all the time you need to study the issue.

I would myself love to try mashing something but I doubt the company would allocate schedule.

@urza
Copy link

urza commented Apr 16, 2022

Hello, was there any progress on this issue?

If we could have what is described here as Example 2: Online Backup of a Running Database that would be extremely useful.

@ajcvickers
Copy link
Member

@urza This issue is in the Backlog milestone. This means that it is not planned for the next release (7.0). We will re-assess the backlog following the this release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you.

@TimeWanderer

This comment was marked as duplicate.

@AnishaAh

This comment was marked as duplicate.

@LukasKubicek

This comment was marked as duplicate.

@oliome

This comment was marked as duplicate.

@roji
Copy link
Member

roji commented Jan 4, 2024

Everyone, please upvote (👍) the top-issue above, and refrain from posting more "me too" comments. We do look at the number of votes when deciding what to work on, but this issue currently has only 24 votes, making it quite low on the priority list.

@oliome

This comment was marked as resolved.

@faridmzd
Copy link

faridmzd commented Mar 12, 2024

hey, currently i'm working on .net maui blazor hybrid, im using sqlite and ef core. My problem is after online backup backup file remains open even though i tried every approach to close it

async Task BackUpLocalDb(AppDBContext dBContext)
{
    using (var source = new SqliteConnection(dBContext.Database.GetConnectionString()))
    using (var destination = new SqliteConnection("Data Source=C:\\Users\\farid\\source\\repos\\Swietlica\\WhoIsHere\\BackupDb\\SwietlicaDatabaseBackup.db"))
    {
        //try
        //{

        await source!.OpenAsync();
        await destination.OpenAsync();
        source.BackupDatabase(destination);
        //}
        //finally
        //{
        //    // Ensure closure and disposal even if exceptions occurs
        //    await source.CloseAsync();
        //    await sourceAsSqlite.CloseAsync();// Or if unavailable, use using statement
        //    await destination.CloseAsync(); // Or if unavailable, use using statement
        //    await source.DisposeAsync();
        //    await sourceAsSqlite.DisposeAsync();
        //    await destination.DisposeAsync();
        //}
    }
        var stream = File.Open("C:\\Users\\farid\\source\\repos\\Swietlica\\WhoIsHere\\BackupDb\\SwietlicaDatabaseBackup.db", FileMode.Open);
}

@oliome
Copy link

oliome commented Mar 12, 2024

hey, currently i'm working on .net maui blazor hybrid, im using sqlite and ef core. My problem is after online backup backup file remains open even though i tried every approach to close it

async Task BackUpLocalDb(AppDBContext dBContext) { using (var source = new SqliteConnection(dBContext.Database.GetConnectionString())) using (var destination = new SqliteConnection("Data Source=C:\Users\farid\source\repos\Swietlica\WhoIsHere\BackupDb\SwietlicaDatabaseBackup.db")) { //try //{

    await source!.OpenAsync();
    await destination.OpenAsync();
    source.BackupDatabase(destination);
    //}
    //finally
    //{
    //    // Ensure closure and disposal even if exceptions occurs
    //    await source.CloseAsync();
    //    await sourceAsSqlite.CloseAsync();// Or if unavailable, use using statement
    //    await destination.CloseAsync(); // Or if unavailable, use using statement
    //    await source.DisposeAsync();
    //    await sourceAsSqlite.DisposeAsync();
    //    await destination.DisposeAsync();
    //}
}
    var stream = File.Open("C:\\Users\\farid\\source\\repos\\Swietlica\\WhoIsHere\\BackupDb\\SwietlicaDatabaseBackup.db", FileMode.Open);

}

I would try SqliteConnection.ClearAllPools().

@ajcvickers ajcvickers removed the good first issue This issue should be relatively straightforward to fix. label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests