Skip to content

Support migration to repository format with compression#3704

Merged
fd0 merged 15 commits intorestic:masterfrom
MichaelEischer:compression-migrations
May 29, 2022
Merged

Support migration to repository format with compression#3704
fd0 merged 15 commits intorestic:masterfrom
MichaelEischer:compression-migrations

Conversation

@MichaelEischer
Copy link
Copy Markdown
Member

@MichaelEischer MichaelEischer commented Apr 11, 2022

What does this PR change? What problem does it solve?

This is the second part of #3666. It adds support to migrate existing repositories to the latest repository format version.

Left-over todos from #3666:

  • Tests which explicitly test both old and new repository format
  • Document --repository-format option
  • Document format migration
  • Improve migration codepaths
  • check progress for the migrate command

Was the change previously discussed in an issue or on the forum?

Fixes #3666.

Checklist

  • I have read the contribution guidelines.
  • I have enabled maintainer edits.
  • I have added tests for all code changes.
  • I have added documentation for relevant changes (in the manual).
  • There's a new file in changelog/unreleased/ that describes the changes for our users (see template).
  • I have run gofmt on the code in all commits.
  • All commit messages are formatted in the same style as the other commits in the repo.
  • I'm done! This pull request is ready for review.

@MichaelEischer MichaelEischer mentioned this pull request Apr 11, 2022
14 tasks
@fd0 fd0 force-pushed the compression-migrations branch from be2f5e0 to 6159a1b Compare April 30, 2022 08:59
@fd0
Copy link
Copy Markdown
Member

fd0 commented Apr 30, 2022

I've rebased this branch onto #3666

@MichaelEischer MichaelEischer force-pushed the compression-migrations branch from 6159a1b to a2210f6 Compare April 30, 2022 09:50
@kakra

This comment was marked as off-topic.

@MichaelEischer

This comment was marked as off-topic.

@thedaveCA

This comment was marked as off-topic.

@fd0

This comment was marked as off-topic.

@fd0
Copy link
Copy Markdown
Member

fd0 commented Apr 30, 2022

Please keep the comments and discussions in this PR related to the code (otherwise we'll get buried by comments!).

Please ask questions in the forum. Thanks a lot!

@MichaelEischer MichaelEischer force-pushed the compression-migrations branch 2 times, most recently from 312ba79 to eccc7e3 Compare May 1, 2022 10:34
@MichaelEischer
Copy link
Copy Markdown
Member Author

I've replaced the compress_repo_v2 migration with a new parameter for prune. That way we get all the functionality of prune like limiting how much data is rewritten and also avoid correctness issues from creeping in.

@MichaelEischer
Copy link
Copy Markdown
Member Author

I wonder whether the upgrade_repo_v2 migration should first try to just overwrite the config file, all backends except the rest-server and the mem backend seem to allow that. It would result in slightly different codepaths depending on the backend, but would have the huge benefit for backends that allow atomic replacements, that there's less that can go wrong.

@fd0
Copy link
Copy Markdown
Member

fd0 commented May 1, 2022

Oh, good idea! I didn't know that we allow overwriting files in the backends. I thought we open files (in sftp and local) with O_CREATE and O_EXCL... at least we used to do that at some point.

@greatroar
Copy link
Copy Markdown
Contributor

@fd0 And they should: I suspect what @MichaelEischer means is "create at temporary path" + "move into place".

@fd0
Copy link
Copy Markdown
Member

fd0 commented May 1, 2022

Ah! It was dropped when we switched to temporary files. Hm. Maybe we should look into restoring that behavior with local and sftp backends (in a separate issue though).

@MichaelEischer
Copy link
Copy Markdown
Member Author

@fd0 And they should: I suspect what @MichaelEischer means is "create at temporary path" + "move into place".

Since the changes to atomically create files in local/sftp, these backends already creates a temporary file and then move it into place. The Azure/GS/S3/Swift backends also support atomic replacements for files.

Maybe we should look into restoring that behavior with local and sftp backends (in a separate issue though).

For what purpose? The normal files which use a hash as filename don't care because the file content will be identical. And for the config file it shouldn't matter either. Either you're able to overwrite/delete that file or not.

@MichaelEischer
Copy link
Copy Markdown
Member Author

MichaelEischer commented May 1, 2022

Ah, I just noticed that sftp doesn't overwrite existing files. It's using Rename and not PosixRename. Rename uses the semantic where the target file must not exist yet. AFAIK the openssh implementation hardlinks the temporary file to its new name before deleting the directory entry for the temporary file. I'm not sure it's worth the trouble to replicate that behavior for the local backend.

And for the cloud backends we cannot prevent atomic overwrites either, we could check whether a file exists first, but that costs an additional API call. (and might lead to consistency problems on S3-like backends)

@MichaelEischer
Copy link
Copy Markdown
Member Author

The repo format migration now sort of runs check before upgrading to ensure that the repository is in a good state. There is no interactive output yet as that requires some changes to how migrations works. The upgrade checks are ideally combined with #3730 which warns about a few legacy variants of repo v1.

@MichaelEischer MichaelEischer force-pushed the compression-migrations branch from 977077d to c1bbbcd Compare May 9, 2022 20:32
@MichaelEischer
Copy link
Copy Markdown
Member Author

The migrate command now directly runs check for upgrade_repo_v2. That way we get check progress information and don't have to reimplement check within a migration.

@fd0 fd0 merged commit d2c5843 into restic:master May 29, 2022
@MichaelEischer MichaelEischer deleted the compression-migrations branch May 29, 2022 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants