Skip to content

WIP: Add backup & restore commands #26944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from

Conversation

lunny
Copy link
Member

@lunny lunny commented Sep 6, 2023

This is a new method to backup database into a fixture-like yml files and then restoring to other databases become more easier.

How to backup a database into a fixture directory? Run

./gitea backup --dir-path=./backup

This will generate yml files per Gitea's database tables. One table one yaml file.

$ ls
access.yml                    commit_status.yml             language_stat.yml             project_issue.yml             star.yml
access_token.yml              commit_status_index.yml       lfs_lock.yml                  protected_branch.yml          stopwatch.yml
action.yml                    dbfs_data.yml                 lfs_meta_object.yml           protected_tag.yml             system_setting.yml
...

How to restore a directory with these fixtures files into a database? Run

./gitea restore --dir-path=./backup

ToDo List:

  • Keep columns sequence in yml file when backup
  • Add tests for same database
  • Add tests for different database

@lunny lunny added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Sep 6, 2023
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 6, 2023
@silverwind
Copy link
Member

Sounds interesting, this could enable easy migration between databases.

@a1012112796
Copy link
Member

@lunny I had writen a fixture dumpper also, would you like to have a look :) #26594

@lng2020
Copy link
Member

lng2020 commented Sep 27, 2023

Testfixture itself support the backup/restore command. Maybe we can reuse those commands?

# load
testfixtures -d postgres -c "postgres://user:password@localhost/database" -D testdata/fixtures
# dump
testfixtures --dump -d postgres -c "postgres://user:password@localhost/database" -D testdata/fixtures

ref(https://github.com/go-testfixtures/testfixtures/blob/master/cmd/testfixtures/testfixtures.go)

@wxiaoguang
Copy link
Contributor

Is it the right way to use yaml like this?

Suppose the user have a large database (I know some users have a >1G action table), would the large yaml files be unmarshaled into memory and cause problems?

start := 0

for {
objs, err := e.Table(table.Name).Limit(bufferSize, start).QueryInterface()
Copy link
Member Author

Choose a reason for hiding this comment

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

@wxiaoguang I don't think we read all records from database to memory. Take a look at this, only 100 records every time. For restoring, testfixture will read the whole yaml content into memory when generating SQL files. That maybe consumes much memories.

Copy link
Contributor

Choose a reason for hiding this comment

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

For restoring, testfixture will read the whole yaml content into memory when generating SQL files. That maybe consumes much memories.

I meant this

@lunny
Copy link
Member Author

lunny commented Jan 30, 2025

Close as I'm not sure if it's a good idea for a big instance. Maybe improve the current SQL based implementation is better.

@lunny lunny closed this Jan 30, 2025
@lunny lunny deleted the lunny/backup_restore branch January 30, 2025 05:45
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Apr 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants