Skip to content

feat(restore)!: restore multi-repository backups to <registry>[/<namespace>] - #2376

Merged
TerryHowe merged 4 commits into
oras-project:mainfrom
Orion777-cmd:feat/restore-multi-repo
Nov 27, 2026
Merged

TerryHowe merged 4 commits into
oras-project:mainfrom
Orion777-cmd:feat/restore-multi-repo

Conversation

@Orion777-cmd

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
Implements Mode 1 ("Direct Restore") from the proposal in #2358. oras restore now treats its argument as <registry>[/<namespace>] and restores each artifact to <target>/<source repository>, so a backup with several repositories can be restored, including repositories that share a tag.

  • Adds --preserve-source-registry to keep the source registry in the target path.
  • Detects target collisions and invalid target repositories before pushing anything.
  • --dry-run and the normal output report the source → target mapping.
  • Specified tags (<target>:v1,v2) match in every repository of the backup.
  • Tag-only backups from earlier versions still restore to the given <registry>/<repository>.

Open question: tag filtering on a bare registry target (harbor.local:v1) is ambiguous with a port, so tags currently need a namespace (harbor.local/ns:v1). Happy to change this.

Opened as a draft until #2358 is agreed.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2364

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update? (the restore target changes; release notes should call it out)
  • Does this introduce breaking changes that would require an announcement or bumping the major version? (yes, the restore target interpretation; restore is experimental, as noted in feat(restore): restore multi-repository backups to <registry>[/<namespace>] #2364)
  • Do all new files have an appropriate license header? (no new files)

@TerryHowe

Copy link
Copy Markdown
Member

Thanks for picking this up! Mode 1 is in good shape: the target mapping, the collision check before pushing (including --dry-run), and the status-handler fetcher fix all look right. I've updated #2364 and #2358 after reviewing this, and one change is needed here:

Please drop tag selection from the target argument. With harbor.local/myproject:v1, the :v1 reads like a destination tag, but here it filters the source, and a backup of docker.io/library/redis:v1 lands in harbor.local/myproject/library/redis:v1. Selection is moving to a follow-up as repeatable --include [<registry>/]<repository>[:<tag>] patterns matched against the source references (Mode 2 in the updated #2358), so the target argument only ever says where things go. For this PR:

  • parseRestoreTarget accepts only <registry>[/<namespace>] and rejects :tag or @digest with a clear error (something like "selecting tags in the restore target is not supported; restore copies every artifact in the backup"). Please reject rather than ignore, so existing <repo>:v1,v2 scripts fail visibly instead of restoring everything somewhere new. This also settles your bare-registry/port question.
  • Remove the specified-tags path from resolveRestoreRefs, and the tests and e2e cases that use it ("multiple tags", "multiple tags with referrers").
  • Update the Use: string and examples to match.

Keeping tag-only backup support as you have it is right; that's what #2364 asks for.

A few smaller things:

  • --preserve-source-registry fails for any source registry with a port (localhost:5000/repo → harbor.local/localhost:5000/repo is invalid). That's fine for now, but please say so in the flag help or the error so it isn't a surprise.
  • The collision error reports only the first pair; listing every colliding repository (as in the proposal's example) helps with large backups.
  • restoreOptions.repository now holds a registry or namespace; renaming it to target would make that clearer.
  • Optional: an e2e test with a bare-registry target and a backup of two repositories would cover the main new path end to end.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #2364: e2e cases for a multi-repository restore to a bare registry, --preserve-source-registry, the collision error and tag rejection are not addressed.

Comment thread cmd/oras/root/restore.go Resolved
Comment thread cmd/oras/root/restore.go Resolved
Comment thread cmd/oras/root/restore.go Resolved
Comment thread cmd/oras/root/restore_test.go Resolved
Comment thread test/e2e/suite/command/restore.go Resolved
Comment thread cmd/oras/root/restore.go Resolved
Comment thread cmd/oras/root/restore.go Resolved
Comment thread test/e2e/suite/command/restore.go Resolved
Comment thread test/e2e/suite/command/restore.go Resolved
Comment thread test/e2e/suite/command/restore.go Resolved
Comment thread test/e2e/suite/command/restore.go Resolved
Comment thread test/e2e/suite/command/restore.go Resolved
Comment thread test/e2e/suite/command/restore.go Resolved
Comment thread test/e2e/suite/command/restore.go Resolved
Comment thread test/e2e/suite/command/restore.go Resolved
Comment thread test/e2e/suite/command/restore.go Resolved
Comment thread test/e2e/suite/command/restore.go Resolved
@Orion777-cmd

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review! Updated:

  • Tags and digests in the target are now rejected, and tag selection is removed (including the "multiple tags" tests).
  • parseRestoreTarget follows your suggestion but returns only the target, since there are no tags left to return.
  • Every colliding pair is reported, the port limitation is documented in the flag help, and repository is renamed to target.
  • --preserve-source-registry with a source registry that has a port now fails with an error that says so, in addition to the flag help.
  • Applied the e2e suggestions and added e2e cases for a multi-repository restore to a bare registry, --preserve-source-registry, collisions, and a tag in the target.
  • Also updated the beginner e2e tests whose error message changed, and the non-existent-registry test so it still reaches the network.

@Orion777-cmd
Orion777-cmd marked this pull request as ready for review November 27, 2026 10:18
Comment thread cmd/oras/root/restore.go Resolved
@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.26923% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.70%. Comparing base (1f32ca8) to head (2ed6fa6).

Files with missing lines Patch % Lines
cmd/oras/root/restore.go 93.87% 3 Missing and 3 partials ⚠️
cmd/oras/internal/display/status/tty.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2376      +/-   ##
==========================================
- Coverage   90.73%   90.70%   -0.03%     
==========================================
  Files         157      157              
  Lines        7069     7111      +42     
==========================================
+ Hits         6414     6450      +36     
- Misses        381      384       +3     
- Partials      274      277       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread cmd/oras/root/restore.go Resolved
…space>]

Restore each artifact in a backup to <target>/<source repository> instead
of pushing every artifact into one repository. The target argument is now
<registry>[/<namespace>], so repositories with the same tag no longer
collide.

- Add --preserve-source-registry to keep the source registry in the target
  repository path.
- Detect two source repositories mapping to the same target repository,
  and invalid target repositories, before anything is pushed.
- Report the source and target of each artifact, including in --dry-run.
- Match specified tags in every repository of the backup.
- Tag-only backups from earlier versions still restore to the given
  <registry>/<repository>.

BREAKING CHANGE: `oras restore --input backup.tar registry.com/team/repo`
now restores a backup of `src.com/team/repo:tag` to
`registry.com/team/repo/team/repo:tag`.

Fixes oras-project#2364

Signed-off-by: orion777-cmd <[email protected]>
- Accept only <registry>[/<namespace>] as the restore target and reject
  a tag or digest in it, instead of using tags to select artifacts.
- Report every colliding pair of source repositories.
- Explain in the flag help and the error that --preserve-source-registry
  does not support source registries with a port.
- Rename restoreOptions.repository to target.
- Add e2e cases for restoring several repositories to a registry,
  collisions, --preserve-source-registry, and a tag in the target.

Signed-off-by: orion777-cmd <[email protected]>
@Orion777-cmd
Orion777-cmd force-pushed the feat/restore-multi-repo branch from f91c6d0 to 2ed6fa6 Compare November 27, 2026 12:39

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@TerryHowe
TerryHowe merged commit 92f15c6 into oras-project:main Nov 27, 2026
10 checks passed
@TerryHowe

Copy link
Copy Markdown
Member

Thanks!

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.

feat(restore): restore multi-repository backups to <registry>[/<namespace>]

2 participants