Skip to content

fix: clear existing volume before restore - #18433

Closed
LZY-SPCA wants to merge 1 commit into
infiniflow:mainfrom
LZY-SPCA:fix-migration-restore-volume
Closed

LZY-SPCA wants to merge 1 commit into
infiniflow:mainfrom
LZY-SPCA:fix-migration-restore-volume

Conversation

@LZY-SPCA

Copy link
Copy Markdown

What does this PR do?

Clear the contents of an existing Docker volume before restoring backup data.

Currently, migration.sh restore extracts the backup archive directly into an existing volume. tar xzf overwrites files that exist in the archive, but it does not remove files that exist only in the target volume.

As a result, restoring into an existing volume performs a merge instead of an exact restore.

This can cause problems for stateful services such as MySQL. In my case, stale InnoDB redo log files remained after restore and caused MySQL to fail during startup with errors such as:

[ERROR] [InnoDB] Missing redo log file
[ERROR] [InnoDB] Plugin initialization aborted with error Generic error
[ERROR] Failed to initialize DD Storage Engine
[ERROR] Data Dictionary initialization failed
[ERROR] Aborting

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Aug 18, 2026
@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bb47b818-b749-4387-b7cf-dfed7e1820e0

📥 Commits

Reviewing files that changed from the base of the PR and between 4a3b20a and 1eafa5a.

📒 Files selected for processing (1)
  • docker/migration.sh

Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The Docker migration script now clears existing volume contents before restoring backup data. Newly created volumes keep their existing behavior.

Changes

Docker volume restore

Layer / File(s) Summary
Clear existing volumes before restore
docker/migration.sh
The script uses find to empty existing Docker volumes before extracting backup data. Newly created volumes are not cleared.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 1eafa

This narrowly scoped change makes volume restores exact by clearing stale contents first; no actionable merge-blocking risk remains after normal checks and review.

Poem

I’m a rabbit with a backup to bear,
I clear old volume contents with care.
Fresh volumes stay bright,
Restores now start right,
And clean data hops everywhere.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: clearing existing Docker volumes before restore.
Description check ✅ Passed The description explains the change, background problem, affected restore behavior, and MySQL failure symptoms, but it does not use the required Summary heading.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JinHai-CN
JinHai-CN requested review from asiroliu and myf-bee August 18, 2026 11:09

@myf-bee myf-bee left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is recommended that the volume cleanup operation be performed by the user themselves. Instructions for this operation are provided below.

@asiroliu

Copy link
Copy Markdown
Collaborator

@LZY-SPCA
I think directly deleting the contents of an existing volume is too risky.

I suggest that during restore, if the target volume already exists, we should fail with an error instead of deleting or overwriting its contents. The error message can provide the command for manually removing the volume, leaving that decision explicitly to the user.

@LZY-SPCA

Copy link
Copy Markdown
Author

I agree that automatically clearing an existing volume during restore may be too destructive.

I think there are two safer alternatives:

  1. Update the migration documentation to explicitly require restoring into empty volumes. For example, the documented restore flow could include:

    • stop the RAGFlow services;
    • remove the existing volumes if the user intends to fully replace the current data;
    • run docker compose create to create empty volumes managed by Docker Compose without starting the services;
    • run migration.sh restore;
    • then start RAGFlow with docker compose up -d.
  2. Alternatively, migration.sh restore could detect that a target volume already exists and abort with a clear error message instead of extracting the backup on top of the existing contents. The message could instruct the user to remove or clear the existing volume before retrying the restore.

The main issue I would like to avoid is the current behavior where tar xzf restores the backup into an existing non-empty volume. This performs a merge rather than an exact restore, because files that are not present in the backup remain in the volume. For stateful services such as MySQL or Elasticsearch, this can leave stale files and cause consistency problems.

I am fine with either updating the documentation or changing the restore behavior to reject non-empty/existing volumes. Both approaches would be safer than silently merging the backup with existing volume contents.

@myf-bee

myf-bee commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

I agree to address this issue first via documentation in this PR#18626. Thank you!

@LZY-SPCA LZY-SPCA closed this Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants