Commit Graph
137 Commits
Author SHA1 Message Date
Kenneth Skovhede f03cf2f7a3 Detatch options on controller
When creating a new controller, the options dictionary was used by-reference.

This meant that code could update the options dictionary *after* creating the controller, which would not be thread-safe.

It does not have much effect on regular operations as the normal method is to create the dictionary, pass it, and not modify it.

But in the tests, we frequently re-use the dictionary and update it with new values to test various cases.

Due to the dictionary being a reference, the controller would update the dictionary to fit the operations, but this would reflect back into the tests, meaning that some tests were being run with options that were not supposed to be there.

This meant that at least two edge cases that we test for were never found to have errors, even though they do.

The first issue is the listing of files using a non-default blocksize. The second issue is recreating the database with a non-default file-hash algorithm.

This PR removes the reference passing, and fixes the issues that were uncovered.
2026-05-14 17:59:49 +02:00
Kenneth Skovhede 179d1ceb47 Make controller Async
This PR has a large blast radius because it takes the final step and bumps up the Controller to be fully async.

We have historically done a piece-by-piece update, so all operations were already async but the controller interface was kept synchronous.

With this update, the controller is now fully async and all tests are updated.

Most places where the new C# compiler warns about function names not ending in `Async` were also adressed, giving a massive refactor change.

Functionally, no changes are done.
2026-05-13 15:04:13 +02:00
Kenneth Skovhede a28b122901 Fixed empty file issue
This PR fixes an issue where backups of an empty file could prevent the backups running after a database recreate.

The issue would not prevent restore or backup, but in the case the user decided to rebuild the database, empty files could in some cases trigger the database consistency validation and prevent backups from running on the recreated database.

This fixes #6822
2026-04-22 14:08:40 +02:00
Kenneth Skovhede c0f40e19ca Updated copyright year to 2026 across the project 2026-04-16 15:21:24 +02:00
Kenneth Skovhede 84cc4005b1 Fix restore without local db
This fixes a bug where restoring with `--no-local-db` and `--version=0` would fail because the database consistency check sees that data is missing.

The missing data is intentional in this case, as we deliberately recreate a partial database.

The PR adds a test for this scenario and fixes the validation to allow for the partial database. Additionally, the partial database is marked as such, in case it is not correctly deleted after the restore.
2026-03-14 12:02:53 +01:00
Kenneth Skovhede a31d6d4655 Fixed checks handling path traversal with mixed directory separator characters 2026-02-05 17:15:06 +01:00
Kenneth Skovhede 655d6cbe65 Prevent restore target escape
This PR adds checks on limited restores, where the user has asked for files to be restored within a specific folder.

This PR adds explicit checks to ensure that the restore data cannot accidentially or maliciously constructed in such a way that it will affect files outside of the restore target folder.
2026-01-27 15:51:30 +01:00
Kenneth Skovhede 1523f730e3 Added support for storing metadata in the database 2026-01-14 10:01:20 +01:00
Kenneth Skovhede 6e6e993765 Fixed issues with database transaction not being comitted.
Renamed the options to be more descriptive.
Rewrote the dependency query to be more readable and also check for metadata dependency.

Fixed an edge case where there were no modified files, and no new backup is created.

Fixed some issues with local/utc datetime compares.

Fixed logic for deleting filesets to only look at the filesets themselves. This makes the version lock follow the dlist file, and can create "dangling" volumes that have no filesets, but these will be picked up by compaction.

Updated tests to work correctly.

Added lock-info update option for the backup recreate call, so the UI can also re-create lock information on database rebuilds.
2025-12-17 22:27:38 +01:00
Carl Johnsen 2412800c0c Removed the sqlite page cache option. It should be set through the environment variable, or some other way of providing a custom database configurotion 2025-06-19 11:41:39 +02:00
Carl Johnsen 32efa4b845 Updated all of the handler calls to database methods to forward their cancellation token 2025-06-19 09:47:33 +02:00
Carl Johnsen 9ac583db94 Made all relevant using statements use await to use DisposeAsync 2025-06-18 11:53:11 +02:00
Carl Johnsen baab370046 Added the final docstrings 2025-06-18 08:26:20 +02:00
Carl Johnsen 3d11a05400 Added .ConfigureAwait(false) to all of the await statements 2025-06-12 08:34:29 +02:00
Carl Johnsen d78348de81 Removed TODOs 2025-06-11 11:48:16 +02:00
Carl Johnsen 85e6f45338 Moved some of the commits to transactions outside of database methods, as this more closely mimics the commit flow of the old IDb backend.
This was especially needed due to the Microsoft.Data.Sqlite backend not supporting nested transactions.
2025-06-03 21:44:55 +02:00
Carl Johnsen 6c7e67dd28 Post master merge fixes 2025-05-22 14:35:15 +02:00
Carl Johnsen a37f0dda31 Merge branch 'master' into performance/mssqlite-async 2025-05-22 14:09:17 +02:00
Carl Johnsen cdba7ef6e9 Updated Utility to use the new async database methods 2025-05-22 08:25:25 +02:00
Carl Johnsen 3fe3e113a7 Updated some of the database calls in RecreateDatabaseHandler to match the new signatures 2025-05-22 06:14:51 +02:00
Carl Johnsen fb2c9d9b9a Simplification and syntactic changes 2025-05-16 12:21:24 +02:00
Carl Johnsen 45902c2c2d Removed the BeginTransaction wrapper function from LocalDatabase 2025-05-16 12:21:24 +02:00
Carl Johnsen 9fcad32058 Updated RecreateDatabaseHandler to utilize the new async interface 2025-05-16 12:21:24 +02:00
Kenneth Skovhede 34a034d96c Simplified recreate logic slightly 2025-05-16 10:34:19 +02:00
Kenneth SkovhedeandGitHub 1bbe04a782 Merge branch 'master' into feature/add-sqlite-cache-value 2025-04-25 13:58:24 +02:00
Kenneth Skovhede 23db3fd090 Added flag to ignore updating to existing version
This fixes #4604

This fixes #3587

This fixes #2275
2025-04-23 17:05:40 +02:00
Kenneth Skovhede 0a7a1cd689 Added option to set the SQLite page cache
This adds an extra option to allow setting the SQLite page cache size as a regular option.

Prior to this commit it was only possible to set the SQLite page cache size via environment variables.

The option to use environment variables is preserved, and as options from the environment variable are applied after the new setting, environment variables take precedence.

The default value for the new option is to use 1% of the system memory for the page cache. For the restore process, a connection per worker may be made which defaults to half the number of cores, so the maximum amount of memory is 1% * half the CPU cores.

This is just the upper limit, and SQLite may choose not to use all of it.

This fixes #6178
2025-04-22 14:26:46 +02:00
Kenneth SkovhedeandGitHub cfc322c629 Merge pull request #6122 from duplicati/feature/remove-positional-sql-arguments
Remove positional arguments from SQL queries
2025-04-04 11:49:36 +02:00
Kenneth Skovhede 2060e9067d Clear databases fileset entries prior to recreate 2025-04-03 22:20:42 +02:00
Kenneth Skovhede 73a2f32b05 Stop recreate early if passphrase is missing
If the passphrase is not supplied it will not be possible to recreate the database.

Prior to this commit, attempting this would result in a string of error messages that do not point to the problem.

With this commit, a single error message is given explaining the problem.
2025-04-03 17:07:28 +02:00
Kenneth SkovhedeandGitHub 85f5ddde1d Merge branch 'master' into feature/guard-against-missing-files 2025-03-25 11:39:13 +01:00
Kenneth Skovhede a163f53dba Handle stop exceptions
This adds a common way to catch stop exceptions and handles them so error resilient logic does not continue when a stop exception is thrown.

Previously, the logic would only check for `ThreadAbortException` which was used to signal a stop prior to .NET8.
2025-03-20 22:32:04 +01:00
Kenneth Skovhede d40301b2b7 Guard against fileset errors
This PR adds a few extra consistency checks to the database, so any failure in the operations is detected earlier than before.

Especially when cleaning temporary and partial files, it is important that the deletes do not remove unexpected entries.

Also, after a recreate, repair or purge command, the database consistency is verified, so it becomes easier to identify which operation caused the failure.

To assist in trouble shooting, there is also a more elaborate error message if a fileset discrepancy is detected, that pinpoints which versions are affected.

Finally, the repair command has been extended to support recreating a fileset from the remote data.
2025-03-20 15:59:14 +01:00
Kenneth Skovhede 7f008341df Untangle the results and database
The code was using a two-way reference linking the database to the results and the results to the database.

However, this was not really used so it ended up just cluttering the code. With this commit, the results and databases are no longer keeping track of each other, and the only interaction is when the results are written to the database at the end of the operation.

To ensure result data is always written, this code has been moved into the controller, which will now flush the results for all operations. Prior to this, only some operations would write result data to the log.

The controller now also handles logic for cleaning old log data and invoking the vacuum command.

Fixed a bug due to using System.Text.Json where some attributes from NewtonSoft.Json were being applied and not picked up.
2025-03-20 09:51:49 +01:00
Kenneth Skovhede c1bdaa069e Async operation handlers
Rewrote all operation handlers to be async.
This moves the async/sync threshold out into the controller.

Fixed all the uses of cancellation token in the handlers to use the provided cancellation token.

Introduced a new ReusableTransaction that can be passed around, avoiding a ref parameter passing of the transaction instance.
2025-03-14 10:41:14 +01:00
Kenneth Skovhede 55fc5d2e6c Added support for recreating filesets and remote lists in some scenarios 2025-03-10 14:41:12 +01:00
Kenneth Skovhede 7031bc57b6 Adding ConfigureAwait(false) to all async enumerations 2025-02-18 09:18:36 +01:00
Kenneth Skovhede 536e62275f Changed the logic in recreate to avoid opening the same zip file multiple times. 2025-02-06 21:34:02 +01:00
Kenneth SkovhedeandGitHub d99f74ed94 Rewrite the backend manager. (#5896)
* Rewrite the backend manager.

This creates a new more logic backend manager that handles all backend operations.

For each top-level operation, there is now a single backend manager instance that is passed to sub-commands.

The internals of the backend manager are now rewritten to use async logic instead of threading.

The design uses a single task runner that dispatches operations and honors concurrent settings and limits from one place.

The logic for each operation has been moved into a separate files/classes to make it easier to understand each operation.

This fixes #5804

* Fixed a few issues with not awaiting tasks

* Fixed not creating empty databases

* Fixed an issue with hashes not being recorded on download

* Reworked the download logic to avoid attempting to decrypt the file if it has been modified.

* Review fixes

* Renamed db collector to better reflect the purpose.

* Review fixes
2025-01-28 08:54:50 +01:00
Kenneth SkovhedeandGitHub 6c493186a7 Changed MissingFileDetected message to Warning (#5893)
* Changed `MissingFileDetected` message to `Warning`

* Updated tests to match errors/warning counts
2025-01-22 21:18:33 +01:00
Kenneth SkovhedeandGitHub d64c7e721f Handle duplicated missing blocks (#5858)
* Implemented test for #5845

* Removed unittests not executing cleanup.

* Cleanup commit

* Fixed the query that causes the constraint violation
2025-01-10 09:24:54 +01:00
Kenneth SkovhedeandGitHub 9464caf622 Feature/update license 2025 (#5851)
* Fixed some minor whitespace issues

* Updated all copyright to 2025
2025-01-07 09:40:39 +01:00
Kenneth SkovhedeandGitHub ff1b2b7990 Simplified task control (#5753)
* Simplified task control by having all logic in a single class and using async control mechanism
* Fixed the tests
* Made the marking of a backup partial explicitly communicated if the enumeration process is stopped.
* Added support for pausing active transfers
* Introduced transfer token to abort operations.
* Updated the way LiveControl is emitting events.
* Retains the paused state of the server across reboots, this fixes #5760.
* Reworked the way throttle speeds are propagated through LiveControls.
* Added option to pause transfers in the UI.
* Removed throttle settings from the LiveControls class so it is exclusively handled by the ApplicationSettings.
* Removed `thread-priority` as it does not work at all when tasks are used.
* Fixed the stop dialog and API to only support stop and abort.
* Removed unused variables
2024-12-18 08:27:59 +01:00
Kenneth Skovhede dedee8fd35 Hand-picked the recreate fixes from #4982.
This fixes that the recreate will move unused blocks into the `DeletedBlock` table after the database has been recreated.
Due to this, the disruption test can now be verified.
2024-11-01 15:56:14 +01:00
Kenneth Skovhede 7d43687090 Reverted to materializing the blocklist as we cannot check the hash before, and we need to throw the exception before we insert any entries. 2024-09-09 17:13:59 +02:00
Kenneth Skovhede ff6757877f Fixing the inconsistency check on repair.
Update the SQL to also group on size (just in case).
Renamed the normal read method to signal that it is unverified.
Made the verified reader use enumeration state machine to avoid materializing the list.
`var`-ified some of the test code.
2024-09-09 15:27:37 +02:00
Kenneth Skovhede 17d9b89fbb Merge branch 'master' into fix-repair-index-consistency
# Conflicts:
#	Duplicati/Library/Main/Operation/RecreateDatabaseHandler.cs
2024-09-09 11:49:34 +02:00
Suguru Hirahara 8e85c10754 Set arguments for strings 2024-07-29 11:30:43 -04:00
Kenneth Skovhede c890e824ee Implemented test for reproducing issue #5196
Fixed issue by changing order options are written and verified.
Some whitespace changes due to renaming a method
2024-05-21 15:48:29 +02:00
Kenneth Skovhede 473c6cbbb8 Merge commit '4f577c65a4d8806f79637c50c21ca3a683c5a07a' into feature/kestrel-avalonia-upgrade 2024-03-04 12:21:53 +01:00