summaryrefslogtreecommitdiff
path: root/src/generation.rs
AgeCommit message (Collapse)AuthorFilesLines
2022-05-03refactor: add a builder for file system entriesLars Wirzenius1-19/+8
The previous commit introduced a function to create FilesystemEntry values from arbitrary data. Previously one could only be created from std::fs::Metadata. This complicated our own testing, which (now) needs to construct an arbitrary entry structure. However, while the function added in the last commit was straightforward, it had 11 arguments, and that's hard to keep track of. Replace that function with an EntryBuilder struct, for clarity. Sponsored-by: author
2022-05-03test: add test for storing, retrieving u64::MAX values in JSONLars Wirzenius1-2/+38
The test passes. We create a FilesystemEntry with a length field containing u64::MAX, store that into a generation, and read it back. This works. The entry is serialised into JSON for storing in SQLite, and this proves we can handle any u64 value in an entry. serde_json deals with it fine, and we don't need to worry about it. Sponsored-by: author
2022-04-21feat: change "show-generation" output to JSONLars Wirzenius1-1/+2
This is more friendly towards anyone wanting to use the output in a script. Sponsored-by: author
2022-04-16feat: use one checksum for all chunks in a backupLars Wirzenius1-5/+12
When making a backup, use the same checksum for any chunks it re-uses or creates. This is for performance: if we allowed two checksums to be used, we would have to compute the checksum for a chunk twice, and potentially look up both on the server. This is just a lot of work. Instead, we use only one. The trade-off here is that when (not if) the user wants to switch to a new checksum type, they'll have to do a full backup, uploading all their data to the server, even when it's already there, just with a different checksum. Hopefully this will be rare. Full backups always use the built-in, hardcoded default checksum, and incremental backups use whatever the previous backup used. The default is still SHA256, but this commit add code to support BLAKE2 if we decide to switch that as a default. It's also easy to add support for others, now. BLAKE2 was added to verify that Obnam can actually handle the checksum changing (manual test: not in the test suite). I don't think users need to be offered even the option of choosing a checksum algorithm to use. When one cares about both security and performance, choosing a checksum requires specialist, expert knowledge. Obnam developers should choose the default. Giving users a knob they can twiddle just makes it that much harder to configure and use Obnam. If the choice Obnam developers have made is shown to be sub-optimal, it seems better to change the default for everyone, rather than hope that every user changes their configuration to gain the benefit. Experience has shown that people mostly don't change the default configuration, and that they are especially bad at choosing well when security is a concern. (Obnam is free software. Expert users can choose their checksum by changing the source code. I'm not fundamentally limiting anyone's freedom or choice here.) Users can switch to a new default algorithm by triggering a full backup with the new "obnam backup --full". Sponsored-by: author
2022-03-20feat: allow user to choose backup schema version for new backupsLars Wirzenius1-134/+17
The way this is currently implemented resulted in a lot of code duplication in src/generation.rs. This should be refactored later. My first attempt to do it by adding a trait for a schema variant failed. Sponsored-by: author
2022-03-06perf: cache user and group name lookupsLars Wirzenius1-4/+5
Sponsored-by: author
2022-03-06refactor: use new database abstraction for generationsLars Wirzenius1-301/+51
Sponsored-by: author
2022-03-06refactor: add a high level database abstraction for backupsLars Wirzenius1-7/+1
Sponsored-by: author
2022-03-03refactor: use FileId instead of raw typeLars Wirzenius1-4/+2
This is clearer and less error prone. Sponsored-by: author
2021-12-31feat: compare schema versions for compatibilityLars Wirzenius1-1/+63
When opening a local generation, check that it's compatible with the current version of Obnam. Sponsored-by: author
2021-12-31docs: add documentation comments to crateLars Wirzenius1-3/+58
Also, make it an error for a public symbol to not be documented. Sponsored-by: author
2021-12-05chore: tidy up things found by newer Rust toolchainLars Wirzenius1-6/+5
Sponsored-by: author
2021-11-27feat! turn errors from backup root directory into errorsLars Wirzenius1-0/+3
Previously an error from, say, a missing backup root directory was reported to the user as a warning. Turn it into an error. However, errors reading a file or directory inside the backup root should still be just a warning. Sponsored-by: author
2021-11-20chore: bump dependency on rusqlite to 0.26.1 and fix breakageLars Wirzenius1-5/+5
Sponsored-by: author
2021-10-24feat! store schema version of generation database in the dbLars Wirzenius1-0/+115
Add a new mandatory database table "meta" to the SQLite database the stores information about the files in a backup generation. The idea is for future versions of the Obnam client to be able to be able to restore from backups made by older -- or newer -- versions of Obnam, as far as is reasonable. Add the `obnam gen-info` command to show information about the generation metadata. Sponsored-by: author
2021-08-09refactor: drop NascentGeneration::insert_iterLars Wirzenius1-31/+12
It was only used by a test function, which is now changed to not use it. Add comment to the test function that it's too complicated and things need refactoring. However, that probably needs to wait for new abstractions. Sponsored-by: author
2021-08-09refactor: use for loop over an iterator instead of .insert_iterLars Wirzenius1-3/+0
This makes the code more explicit, which is good for now, and is a step towards making it all use async. There will be a need to refactor this further with better abstractions, once async works. Sponsored-by: author
2021-08-09refactor: call NascentGeneration::insert from ::insert_iterLars Wirzenius1-4/+1
This is a step towards getting rid of insert_iter entirely, which would make it easier to make `obnam backup` use async. I originally split insert_iter so I could use a single transaction for inserting many rows, but it seems to not be needed for speed after all. I've benchmarked backing up a large file with and without this change, and there's no real difference. I've not benchmarked with a large number of files. Even if there's a performance hit from using multiple transactions, my hope is that by being able to use more CPUs/threads for backing up will outweigh that by far. Sponsored-by: author
2021-08-01refactor: use a struct for GenIdLars Wirzenius1-5/+28
This means a ChunkId can't be used instead. Sponsored-by: author
2021-08-01refactor: add a type alias for generation idsLars Wirzenius1-0/+3
This will make it harder to accidentally use a string. Can still be confused with a chunk id. Sponsored-by: author
2021-07-30cleanup: fix things rustc/clipppy now complain aboutLars Wirzenius1-4/+4
Mostly https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow. Sponsored-by: author
2021-07-28Mark CACHEDIR.TAGs in the databaseAlexander Batischev1-23/+114
In the following commits, we'll use this to check if a tag existed before.
2021-07-21Replace LocalGenerationResult with plain ResultAlexander Batischev1-24/+32
I do not plan to simplify the `T` in the return type of `get_file_and_fileno` because that function is only ever called from inside the module; it doesn't seem worthwhile to introduce a new type there.
2021-07-21Replace NascentResult with plain ResultAlexander Batischev1-5/+3
2021-07-21backup_run: replace tuple with a structAlexander Batischev1-4/+4
2021-07-21Replace BackupResult with plain ResultAlexander Batischev1-2/+2
2021-07-05refactor: code to run backups to have less repetitionLars Wirzenius1-1/+9
This should make it easier to introduce async, later.
2021-04-29feat: improve error messagesLars Wirzenius1-8/+8
All unclear error messages should now be clearer. For example, all the ones related to a file mention the file name and the attempted operation that failed.
2021-04-26Port chunkids() to the iterator APIAlexander Batischev1-10/+17
2021-04-26Generalize the machinery to arbitrary result typesAlexander Batischev1-18/+55
2021-04-26Extend the iterator to users of LocalGeneration::files()Alexander Batischev1-2/+2
2021-04-26Use an iterator internally for LocalGenerationAlexander Batischev1-19/+32
This adds the machinery. We have to keep the compiled SQL query while the iterator is in use, so we wrap it in an `SqlResults` struct which the iterator borrows.
2021-04-26Expose fallibility of individual SQL resultsAlexander Batischev1-6/+14
`LocalGeneration::sql::files()` runs an SQL query, iterates over the results and collects the rows into a `Vec`. This can fail at any step: the query might fail to run, or one of the rows might fail to be fetched or processed. Right now, we lump all those failures into a `Result` that wraps the whole return value. This is only possible because we process each row before returning. Once `Vec` is replaced by an iterator, we won't have that luxury anymore, so we now wrap each individual element into its own `Result` (as well as wrapping the whole vector into a `Result` of its own).
2021-04-06chore: clean up unnecessary use of ? based on clippy reportsLars Wirzenius1-6/+6
2021-03-27refactor: drop unused lifetime annotationLars Wirzenius1-1/+1
2021-03-27refactor: drop unnecessary conversions to the same typeLars Wirzenius1-1/+1
2021-03-27refactor: avoid confusing function name from_strLars Wirzenius1-1/+1
2021-03-12feat: show warnings for any problems backing up filesLars Wirzenius1-5/+14
Previously, we either ignored it or aborted the backup. Neither is good. Now we ignore the problem, except to show a warning at the end of the backup run.
2021-02-04refactor: have per-module error enumsLars Wirzenius1-22/+61
This means that a function that parses step bindings can't return an error that the document is missing a title. Such an error return would be nonsensical, and we use the Rust type system to prevent it, at a small cost of being a bit verbose. Additional benefit is that the library portion of Obnam doesn't return anyhow::Result values anymore.
2021-01-05refactor: add BackedUpFile to avoid using a tupleLars Wirzenius1-4/+34
The struct is easier to use right.
2021-01-05refactor: move policy on whether to back up a file into a moduleLars Wirzenius1-2/+2
This commit also splits up the src/cmd/backup.rs module into other, smaller, more cohesive modules that are easier to understand and use.
2021-01-04refactor: add a type alias for file identifiers in generationsLars Wirzenius1-15/+18
2021-01-04feat! record whether file was backed up and why, in a generationLars Wirzenius1-22/+31
This changes SQL schema.
2021-01-04feat: add an index for chunk ids lookupsLars Wirzenius1-0/+1
2021-01-01feat: use SQL to look up information for a file, by filenameLars Wirzenius1-14/+24
This speeds things up a lot compared to iterating over all files.
2021-01-01feat! use signed 64 bit integers as file numbers, file countsLars Wirzenius1-17/+15
2021-01-01refactor: move SQL use into sub-moduleLars Wirzenius1-58/+92
This keeps all the SQL related functions closer together, making it easier to make changes to them.
2020-12-31feat: incremental backupLars Wirzenius1-0/+32
This uses the previous, latest generation as a guideline to see what is new or changed.
2020-12-31refactor: add LocalGeneration type for read-only operationsLars Wirzenius1-55/+59
This splits the use of NascentGeneration to more cohesive "new generation being built" versus "existing generation being restored".
2020-12-30feat: add GenerationListLars Wirzenius1-0/+1
Various part of Obnam will need to deal with lists of generations. Abstract this.