Cannot migrate database #5851

Closed
opened 2025-11-02 06:38:15 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @lfdmn on GitHub (Aug 13, 2020).

  • Gitea version (or commit ref):
  • Git version:
  • Operating system:
  • Database (use [x]):
    • PostgreSQL
    • [*] MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • [* ] No
    • Not relevant
  • Log gist:

Description

I'm having big troubles moving a gitea instance from my PC to a server. The server runs under docker and for my machine just a simple linux service.

Both PC and server have gitea 1.12.3. Both have MariaDB.

I used
./gitea dump -c /path/to/app.ini

to create a full backup. Then I moved the zip file to the server. Unzipped, moved the git repositories where they belong.

Then for restoring the database:

docker exec -i gitea_db mysql -f --default-character-set=utf8mb4 -ugitea -pgitea gitea < gitea-db.sql

I get a lot of errors. Here are a few:

ERROR 1061 (42000) at line 4: Duplicate key name 'IDX_user_is_active'
ERROR 1061 (42000) at line 5: Duplicate key name 'UQE_user_lower_name'
ERROR 1061 (42000) at line 6: Duplicate key name 'UQE_user_name'
ERROR 1061 (42000) at line 7: Duplicate key name 'IDX_user_created_unix'
ERROR 1061 (42000) at line 8: Duplicate key name 'IDX_user_updated_unix'
ERROR 1061 (42000) at line 9: Duplicate key name 'IDX_user_last_login_unix'
ERROR 1062 (23000) at line 10: Duplicate entry '1' for key 'PRIMARY'
ERROR 1062 (23000) at line 11: Duplicate entry '2' for key 'PRIMARY'
ERROR 1062 (23000) at line 12: Duplicate entry 'damien.lefevre' for key 'UQE_user_lower_name'
ERROR 1061 (42000) at line 473: Duplicate key name 'IDX_public_key_owner_id'
ERROR 1061 (42000) at line 474: Duplicate key name 'IDX_public_key_fingerprint'
ERROR 1061 (42000) at line 521: Duplicate key name 'IDX_access_token_uid'
ERROR 1061 (42000) at line 522: Duplicate key name 'UQE_access_token_token_hash'
ERROR 1061 (42000) at line 523: Duplicate key name 'IDX_access_token_created_unix'
ERROR 1061 (42000) at line 524: Duplicate key name 'IDX_access_token_updated_unix'
ERROR 1061 (42000) at line 527: Duplicate key name 'IDX_repository_lower_name'
ERROR 1061 (42000) at line 528: Duplicate key name 'IDX_repository_is_private'
ERROR 1061 (42000) at line 529: Duplicate key name 'IDX_repository_is_empty'
ERROR 1061 (42000) at line 530: Duplicate key name 'IDX_repository_is_archived'
ERROR 1061 (42000) at line 531: Duplicate key name 'IDX_repository_updated_unix'
ERROR 1061 (42000) at line 532: Duplicate key name 'IDX_repository_created_unix'
ERROR 1061 (42000) at line 533: Duplicate key name 'UQE_repository_s'
ERROR 1061 (42000) at line 534: Duplicate key name 'IDX_repository_name'
ERROR 1061 (42000) at line 535: Duplicate key name 'IDX_repository_is_mirror'
ERROR 1061 (42000) at line 536: Duplicate key name 'IDX_repository_is_fork'
ERROR 1061 (42000) at line 537: Duplicate key name 'IDX_repository_fork_id'
ERROR 1061 (42000) at line 632: Duplicate key name 'UQE_deploy_key_s'
ERROR 1061 (42000) at line 633: Duplicate key name 'IDX_deploy_key_key_id'
ERROR 1061 (42000) at line 634: Duplicate key name 'IDX_deploy_key_repo_id'
ERROR 1061 (42000) at line 637: Duplicate key name 'IDX_collaboration_repo_id'
ERROR 1061 (42000) at line 638: Duplicate key name 'IDX_collaboration_user_id'
...

After that gitea runs but all the organizations are missing and all the links to repositories are broken.

Next I tried to ssh to the DB container and tried to drop all the tables in the database to start clean

SELECT CONCAT('DROP TABLE IF EXISTS `', TABLE_SCHEMA, '`.`', TABLE_NAME, '`;')
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'gitea';

Generating

 DROP TABLE IF EXISTS `gitea`.`access`;                                  
 DROP TABLE IF EXISTS `gitea`.`access_token`;                            
 DROP TABLE IF EXISTS `gitea`.`action`;                                  
 DROP TABLE IF EXISTS `gitea`.`attachment`;                              
 DROP TABLE IF EXISTS `gitea`.`collaboration`;                           
 DROP TABLE IF EXISTS `gitea`.`comment`;                                 
 DROP TABLE IF EXISTS `gitea`.`commit_status`;                           
 DROP TABLE IF EXISTS `gitea`.`deleted_branch`;                          
 DROP TABLE IF EXISTS `gitea`.`deploy_key`;                              
 DROP TABLE IF EXISTS `gitea`.`email_address`;                           
 DROP TABLE IF EXISTS `gitea`.`email_hash`;                              
 DROP TABLE IF EXISTS `gitea`.`external_login_user`;                     
 DROP TABLE IF EXISTS `gitea`.`follow`;                                  
 DROP TABLE IF EXISTS `gitea`.`gpg_key`;                                 
 DROP TABLE IF EXISTS `gitea`.`gpg_key_import`;                          
 DROP TABLE IF EXISTS `gitea`.`hook_task`;                               
 DROP TABLE IF EXISTS `gitea`.`issue`;                                   
 DROP TABLE IF EXISTS `gitea`.`issue_assignees`;                         
 DROP TABLE IF EXISTS `gitea`.`issue_dependency`;                        
 DROP TABLE IF EXISTS `gitea`.`issue_label`;                             
 DROP TABLE IF EXISTS `gitea`.`issue_user`;                              
 DROP TABLE IF EXISTS `gitea`.`issue_watch`;                             
 DROP TABLE IF EXISTS `gitea`.`label`;                                   
 DROP TABLE IF EXISTS `gitea`.`language_stat`;                           
 DROP TABLE IF EXISTS `gitea`.`lfs_lock`;                                
 DROP TABLE IF EXISTS `gitea`.`lfs_meta_object`;                         
 DROP TABLE IF EXISTS `gitea`.`login_source`;                            
 DROP TABLE IF EXISTS `gitea`.`milestone`;                               
 DROP TABLE IF EXISTS `gitea`.`mirror`;                                  
 DROP TABLE IF EXISTS `gitea`.`notice`;                                  
 DROP TABLE IF EXISTS `gitea`.`notification`;                            
 DROP TABLE IF EXISTS `gitea`.`oauth2_application`;                      
 DROP TABLE IF EXISTS `gitea`.`oauth2_authorization_code`;               
 DROP TABLE IF EXISTS `gitea`.`oauth2_grant`;                            
 DROP TABLE IF EXISTS `gitea`.`oauth2_session`;                          
 DROP TABLE IF EXISTS `gitea`.`org_user`;                                
 DROP TABLE IF EXISTS `gitea`.`protected_branch`;                        
 DROP TABLE IF EXISTS `gitea`.`public_key`;                              
 DROP TABLE IF EXISTS `gitea`.`pull_request`;                            
 DROP TABLE IF EXISTS `gitea`.`reaction`;                                
 DROP TABLE IF EXISTS `gitea`.`release`;                                 
 DROP TABLE IF EXISTS `gitea`.`repo_indexer_status`;                     
 DROP TABLE IF EXISTS `gitea`.`repo_redirect`;                           
 DROP TABLE IF EXISTS `gitea`.`repo_topic`;                              
 DROP TABLE IF EXISTS `gitea`.`repo_unit`;                               
 DROP TABLE IF EXISTS `gitea`.`repository`;                              
 DROP TABLE IF EXISTS `gitea`.`review`;                                  
 DROP TABLE IF EXISTS `gitea`.`star`;                                    
 DROP TABLE IF EXISTS `gitea`.`stopwatch`;                               
 DROP TABLE IF EXISTS `gitea`.`task`;                                    
 DROP TABLE IF EXISTS `gitea`.`team`;                                    
 DROP TABLE IF EXISTS `gitea`.`team_repo`;                               
 DROP TABLE IF EXISTS `gitea`.`team_unit`;                               
 DROP TABLE IF EXISTS `gitea`.`team_user`;                               
 DROP TABLE IF EXISTS `gitea`.`topic`;                                   
 DROP TABLE IF EXISTS `gitea`.`tracked_time`;                            
 DROP TABLE IF EXISTS `gitea`.`two_factor`;                              
 DROP TABLE IF EXISTS `gitea`.`u2f_registration`;                        
 DROP TABLE IF EXISTS `gitea`.`upload`;                                  
 DROP TABLE IF EXISTS `gitea`.`user`;                                    
 DROP TABLE IF EXISTS `gitea`.`user_open_id`;                            
 DROP TABLE IF EXISTS `gitea`.`version`;                                 
 DROP TABLE IF EXISTS `gitea`.`watch`;                                   
 DROP TABLE IF EXISTS `gitea`.`webhook`;

On an empty database, I still get 5 errors:

ERROR 1061 (42000) at line 15096: Duplicate key name 'IDX_webhook_repo_id'
ERROR 1061 (42000) at line 15097: Duplicate key name 'IDX_webhook_org_id'
ERROR 1061 (42000) at line 15098: Duplicate key name 'IDX_webhook_is_active'
ERROR 1061 (42000) at line 15099: Duplicate key name 'IDX_webhook_created_unix'
ERROR 1061 (42000) at line 15100: Duplicate key name 'IDX_webhook_updated_unix'

After that, not all organizations a and not all repositories are added.

Links for the repositories are broken. For example I have a organization named tools which has a build-environment repository.

If I go to tools organization, the link for build-environment is https://build-environment/

Same goes for the pull requests. Only few of them are restored and the links lead to page 404.

I dumped both the database schema and they look different although they are from the same gitea version
container.sql.txt
original.sql.txt

Any hints would be greatly appreciated.

Screenshots

Originally created by @lfdmn on GitHub (Aug 13, 2020). <!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue --> <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): - Git version: - Operating system: - Database (use `[x]`): - [ ] PostgreSQL - [*] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [* ] No - [ ] Not relevant - Log gist: ## Description I'm having big troubles moving a gitea instance from my PC to a server. The server runs under docker and for my machine just a simple linux service. Both PC and server have gitea 1.12.3. Both have MariaDB. I used ```./gitea dump -c /path/to/app.ini``` to create a full backup. Then I moved the zip file to the server. Unzipped, moved the git repositories where they belong. Then for restoring the database: ``` docker exec -i gitea_db mysql -f --default-character-set=utf8mb4 -ugitea -pgitea gitea < gitea-db.sql ``` I get a lot of errors. Here are a few: ``` ERROR 1061 (42000) at line 4: Duplicate key name 'IDX_user_is_active' ERROR 1061 (42000) at line 5: Duplicate key name 'UQE_user_lower_name' ERROR 1061 (42000) at line 6: Duplicate key name 'UQE_user_name' ERROR 1061 (42000) at line 7: Duplicate key name 'IDX_user_created_unix' ERROR 1061 (42000) at line 8: Duplicate key name 'IDX_user_updated_unix' ERROR 1061 (42000) at line 9: Duplicate key name 'IDX_user_last_login_unix' ERROR 1062 (23000) at line 10: Duplicate entry '1' for key 'PRIMARY' ERROR 1062 (23000) at line 11: Duplicate entry '2' for key 'PRIMARY' ERROR 1062 (23000) at line 12: Duplicate entry 'damien.lefevre' for key 'UQE_user_lower_name' ERROR 1061 (42000) at line 473: Duplicate key name 'IDX_public_key_owner_id' ERROR 1061 (42000) at line 474: Duplicate key name 'IDX_public_key_fingerprint' ERROR 1061 (42000) at line 521: Duplicate key name 'IDX_access_token_uid' ERROR 1061 (42000) at line 522: Duplicate key name 'UQE_access_token_token_hash' ERROR 1061 (42000) at line 523: Duplicate key name 'IDX_access_token_created_unix' ERROR 1061 (42000) at line 524: Duplicate key name 'IDX_access_token_updated_unix' ERROR 1061 (42000) at line 527: Duplicate key name 'IDX_repository_lower_name' ERROR 1061 (42000) at line 528: Duplicate key name 'IDX_repository_is_private' ERROR 1061 (42000) at line 529: Duplicate key name 'IDX_repository_is_empty' ERROR 1061 (42000) at line 530: Duplicate key name 'IDX_repository_is_archived' ERROR 1061 (42000) at line 531: Duplicate key name 'IDX_repository_updated_unix' ERROR 1061 (42000) at line 532: Duplicate key name 'IDX_repository_created_unix' ERROR 1061 (42000) at line 533: Duplicate key name 'UQE_repository_s' ERROR 1061 (42000) at line 534: Duplicate key name 'IDX_repository_name' ERROR 1061 (42000) at line 535: Duplicate key name 'IDX_repository_is_mirror' ERROR 1061 (42000) at line 536: Duplicate key name 'IDX_repository_is_fork' ERROR 1061 (42000) at line 537: Duplicate key name 'IDX_repository_fork_id' ERROR 1061 (42000) at line 632: Duplicate key name 'UQE_deploy_key_s' ERROR 1061 (42000) at line 633: Duplicate key name 'IDX_deploy_key_key_id' ERROR 1061 (42000) at line 634: Duplicate key name 'IDX_deploy_key_repo_id' ERROR 1061 (42000) at line 637: Duplicate key name 'IDX_collaboration_repo_id' ERROR 1061 (42000) at line 638: Duplicate key name 'IDX_collaboration_user_id' ... ``` After that gitea runs but all the organizations are missing and all the links to repositories are broken. Next I tried to ssh to the DB container and tried to drop all the tables in the database to start clean ``` SELECT CONCAT('DROP TABLE IF EXISTS `', TABLE_SCHEMA, '`.`', TABLE_NAME, '`;') FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'gitea'; ``` Generating ``` DROP TABLE IF EXISTS `gitea`.`access`; DROP TABLE IF EXISTS `gitea`.`access_token`; DROP TABLE IF EXISTS `gitea`.`action`; DROP TABLE IF EXISTS `gitea`.`attachment`; DROP TABLE IF EXISTS `gitea`.`collaboration`; DROP TABLE IF EXISTS `gitea`.`comment`; DROP TABLE IF EXISTS `gitea`.`commit_status`; DROP TABLE IF EXISTS `gitea`.`deleted_branch`; DROP TABLE IF EXISTS `gitea`.`deploy_key`; DROP TABLE IF EXISTS `gitea`.`email_address`; DROP TABLE IF EXISTS `gitea`.`email_hash`; DROP TABLE IF EXISTS `gitea`.`external_login_user`; DROP TABLE IF EXISTS `gitea`.`follow`; DROP TABLE IF EXISTS `gitea`.`gpg_key`; DROP TABLE IF EXISTS `gitea`.`gpg_key_import`; DROP TABLE IF EXISTS `gitea`.`hook_task`; DROP TABLE IF EXISTS `gitea`.`issue`; DROP TABLE IF EXISTS `gitea`.`issue_assignees`; DROP TABLE IF EXISTS `gitea`.`issue_dependency`; DROP TABLE IF EXISTS `gitea`.`issue_label`; DROP TABLE IF EXISTS `gitea`.`issue_user`; DROP TABLE IF EXISTS `gitea`.`issue_watch`; DROP TABLE IF EXISTS `gitea`.`label`; DROP TABLE IF EXISTS `gitea`.`language_stat`; DROP TABLE IF EXISTS `gitea`.`lfs_lock`; DROP TABLE IF EXISTS `gitea`.`lfs_meta_object`; DROP TABLE IF EXISTS `gitea`.`login_source`; DROP TABLE IF EXISTS `gitea`.`milestone`; DROP TABLE IF EXISTS `gitea`.`mirror`; DROP TABLE IF EXISTS `gitea`.`notice`; DROP TABLE IF EXISTS `gitea`.`notification`; DROP TABLE IF EXISTS `gitea`.`oauth2_application`; DROP TABLE IF EXISTS `gitea`.`oauth2_authorization_code`; DROP TABLE IF EXISTS `gitea`.`oauth2_grant`; DROP TABLE IF EXISTS `gitea`.`oauth2_session`; DROP TABLE IF EXISTS `gitea`.`org_user`; DROP TABLE IF EXISTS `gitea`.`protected_branch`; DROP TABLE IF EXISTS `gitea`.`public_key`; DROP TABLE IF EXISTS `gitea`.`pull_request`; DROP TABLE IF EXISTS `gitea`.`reaction`; DROP TABLE IF EXISTS `gitea`.`release`; DROP TABLE IF EXISTS `gitea`.`repo_indexer_status`; DROP TABLE IF EXISTS `gitea`.`repo_redirect`; DROP TABLE IF EXISTS `gitea`.`repo_topic`; DROP TABLE IF EXISTS `gitea`.`repo_unit`; DROP TABLE IF EXISTS `gitea`.`repository`; DROP TABLE IF EXISTS `gitea`.`review`; DROP TABLE IF EXISTS `gitea`.`star`; DROP TABLE IF EXISTS `gitea`.`stopwatch`; DROP TABLE IF EXISTS `gitea`.`task`; DROP TABLE IF EXISTS `gitea`.`team`; DROP TABLE IF EXISTS `gitea`.`team_repo`; DROP TABLE IF EXISTS `gitea`.`team_unit`; DROP TABLE IF EXISTS `gitea`.`team_user`; DROP TABLE IF EXISTS `gitea`.`topic`; DROP TABLE IF EXISTS `gitea`.`tracked_time`; DROP TABLE IF EXISTS `gitea`.`two_factor`; DROP TABLE IF EXISTS `gitea`.`u2f_registration`; DROP TABLE IF EXISTS `gitea`.`upload`; DROP TABLE IF EXISTS `gitea`.`user`; DROP TABLE IF EXISTS `gitea`.`user_open_id`; DROP TABLE IF EXISTS `gitea`.`version`; DROP TABLE IF EXISTS `gitea`.`watch`; DROP TABLE IF EXISTS `gitea`.`webhook`; ``` On an empty database, I still get 5 errors: ``` ERROR 1061 (42000) at line 15096: Duplicate key name 'IDX_webhook_repo_id' ERROR 1061 (42000) at line 15097: Duplicate key name 'IDX_webhook_org_id' ERROR 1061 (42000) at line 15098: Duplicate key name 'IDX_webhook_is_active' ERROR 1061 (42000) at line 15099: Duplicate key name 'IDX_webhook_created_unix' ERROR 1061 (42000) at line 15100: Duplicate key name 'IDX_webhook_updated_unix' ``` After that, not all organizations a and not all repositories are added. Links for the repositories are broken. For example I have a organization named **tools** which has a **build-environment** repository. If I go to tools organization, the link for build-environment is **https://build-environment/** Same goes for the pull requests. Only few of them are restored and the links lead to page 404. I dumped both the database schema and they look different although they are from the same gitea version [container.sql.txt](https://github.com/go-gitea/gitea/files/5069836/container.sql.txt) [original.sql.txt](https://github.com/go-gitea/gitea/files/5069838/original.sql.txt) Any hints would be greatly appreciated. ## Screenshots <!-- **If this issue involves the Web Interface, please include a screenshot** -->
GiteaMirror added the issue/stale label 2025-11-02 06:38:15 -06:00
Author
Owner

@lfdmn commented on GitHub (Aug 13, 2020):

Also I noticed the in my LDAP User Filter, the & was changed to u0026 i.e
(u0026(objectCategory=person)(objectClass=user)(|(sAMAccountName=%[1]s)(mail=%[1]s)))
instead of
(&(objectCategory=person)(objectClass=user)(|(sAMAccountName=%[1]s)(mail=%[1]s)))

@lfdmn commented on GitHub (Aug 13, 2020): Also I noticed the in my LDAP User Filter, the & was changed to u0026 i.e ```(u0026(objectCategory=person)(objectClass=user)(|(sAMAccountName=%[1]s)(mail=%[1]s)))``` instead of ```(&(objectCategory=person)(objectClass=user)(|(sAMAccountName=%[1]s)(mail=%[1]s)))```
Author
Owner

@stale[bot] commented on GitHub (Oct 12, 2020):

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

@stale[bot] commented on GitHub (Oct 12, 2020): This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.
Author
Owner

@zeripath commented on GitHub (Jun 28, 2021):

I'm fairly certain we've fixed this with some fixes to Xorm. Therefore I'm closing this.

@zeripath commented on GitHub (Jun 28, 2021): I'm fairly certain we've fixed this with some fixes to Xorm. Therefore I'm closing this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#5851