Quoting the Gitea docs:
Upgrading from Gogs 0.12.x and above will be increasingly more difficult as the projects diverge further apart in configuration and schema.
Since gogs has now multiple unfixed RCEs and has for a while, it is imperative to either turn it off or migrate. The problem is, what to do if running a version > 0.11.x?
- https://www.sonarsource.com/blog/securing-developer-tools-unpatched-code-vulnerabilities-in-gogs-1/
- https://www.sonarsource.com/blog/securing-developer-tools-unpatched-code-vulnerabilities-in-gogs-2/
- https://fysac.github.io/posts/2024/11/unpatched-remote-code-execution-in-gogs/
- gogs/gogs#7777
Backup everything, if possible do both an archive of your gogs home dire and run ./gogs backup
.
Download and install Gogs 0.11.86:
Install it under a different folder/user, be careful not to overwrite anything. The install data do not matter, just use sqlite3 and install it from scratch.
Once Gogs 0.11.86 has been installed, copy the sqlite database of the 0.11.86 version as 11.db
. Copy the database of the 0.13 version to be migrated as 13.db
.
Run the attached script, as migrate.py 13.db 11.db
.
What the script does is a lossy migration from the newer schema to the older one. It empty the content of the default install, ignore system tables and then copy table by table the data from the newer one to the older one. Some data are discarded, so depending on your configuration this might lose data. However the schema changes are minimal, it will likely not affect you.
Sample output:
python3 migrate.py 13_test.db 11_test.db
Cleared all records from table 'user'.
Cleared all records from table 'public_key'.
Cleared all records from table 'access_token'.
Cleared all records from table 'two_factor'.
Cleared all records from table 'two_factor_recovery_code'.
Cleared all records from table 'repository'.
Cleared all records from table 'deploy_key'.
Cleared all records from table 'collaboration'.
Cleared all records from table 'access'.
Cleared all records from table 'upload'.
Cleared all records from table 'watch'.
Cleared all records from table 'star'.
Cleared all records from table 'follow'.
Cleared all records from table 'action'.
Cleared all records from table 'issue'.
Cleared all records from table 'pull_request'.
Cleared all records from table 'comment'.
Cleared all records from table 'attachment'.
Cleared all records from table 'issue_user'.
Cleared all records from table 'label'.
Cleared all records from table 'issue_label'.
Cleared all records from table 'milestone'.
Cleared all records from table 'mirror'.
Cleared all records from table 'release'.
Cleared all records from table 'login_source'.
Cleared all records from table 'webhook'.
Cleared all records from table 'hook_task'.
Cleared all records from table 'protect_branch'.
Cleared all records from table 'protect_branch_whitelist'.
Cleared all records from table 'team'.
Cleared all records from table 'org_user'.
Cleared all records from table 'team_user'.
Cleared all records from table 'team_repo'.
Cleared all records from table 'notice'.
Cleared all records from table 'email_address'.
Cleared all records from table 'version'.
Database cleared of all records.
Migrated table 'user' with 42 rows.
Migrated table 'public_key' with 20 rows.
Migrated table 'access_token' with 1 rows.
Migrated table 'two_factor' with 3 rows.
Migrated table 'two_factor_recovery_code' with 30 rows.
Migrated table 'repository' with 128 rows.
Migrated table 'deploy_key' with 1 rows.
Migrated table 'collaboration' with 55 rows.
Migrated table 'access' with 263 rows.
Migrated table 'upload' with 0 rows.
Migrated table 'watch' with 245 rows.
Migrated table 'star' with 7 rows.
Migrated table 'follow' with 3 rows.
Migrated table 'action' with 3620 rows.
Migrated table 'issue' with 21 rows.
Migrated table 'pull_request' with 5 rows.
Migrated table 'comment' with 18 rows.
Migrated table 'attachment' with 1 rows.
Migrated table 'issue_user' with 53 rows.
Migrated table 'label' with 0 rows.
Migrated table 'issue_label' with 0 rows.
Migrated table 'milestone' with 0 rows.
Migrated table 'mirror' with 0 rows.
Migrated table 'release' with 0 rows.
Migrated table 'login_source' with 0 rows.
Migrated table 'webhook' with 4 rows.
Migrated table 'hook_task' with 135 rows.
Migrated table 'protect_branch' with 0 rows.
Migrated table 'protect_branch_whitelist' with 0 rows.
Migrated table 'team' with 5 rows.
Migrated table 'org_user' with 30 rows.
Migrated table 'team_user' with 30 rows.
Migrated table 'team_repo' with 35 rows.
Migrated table 'notice' with 1 rows.
Migrated table 'email_address' with 1 rows.
Migrated table 'version' with 1 rows.
Migration complete.
At the end, rollback the version in the target database:
UPDATE version SET version = 13;
Now, copy 11.db back to your Gogs 0.11.86 install and test that it still works. It will require you copying repository data from 0.13 to 0.11 too and maybe some minor configuration changes (check paths, security key).
Check Gogs logs for errors.
read the official Gitea documentation and the issues discussing migration from 0.11.x:
Download Gitea 1.0.2: https://dl.gitea.com/gitea/1.0.2/
Follow the official gitea documentation: copy the config from 0.13 to the gitea default path. TYPE
under [database]
should be renamed to DB_TYPE
. In general try to run ./gitea web
a few times and check output/logs.
Chage all the paths according to the migration procedure described in the documentation, proceed incrementally between major Gitea versions.
In my case I retained users, repositories, groups, avatars, issues, webhooks. Hooks and more features to be checked.
In the admi panel, run
- "Rewrite all update hook of repositories (needed when custom config path is changed)"
- "Rewrite '.ssh/authorized_keys' file (caution: non-Gitea keys will be lost)"
For some reason hooks update did not work for me and the action seems not to do anything. I manually deleted all of them as I did not had any custom one.
yo save me, thanks