How to migrate Gitea

Recently, I buy a new server in Ali cloud HK, whose latency is very low visiting from China mainland. So I decide to migrate all service from RN US LA to this new server.

The first thing is my blog. As it is based on Gitea, so I need to migrate Gitea first. Let’s start it.

How to migrate Gitea

Now we give alias name to two server.

Old server: server A

New server: server B

Environment:

1
2
3
4
5
6
Server A:
Ubuntu 22.04.3 LTS
Gitea version 1.20.4 built with GNU Make 4.2.1, go1.20.8 : bindata, sqlite, sqlite_unlock_notify
Server B:
Ubuntu 22.04.4 LTS
Gitea version 1.21.11 built with GNU Make 4.3, go1.21.8 : bindata, sqlite, sqlite_unlock_notify
  1. Install a brand new Gitea on Server B following installation tutorial in my blog. Please use the same password when create database user in order to avoid bug.

  2. Log in server A as root.

    1
    2
    3
    4
    5
    cd /etc/gitea/
    gitea dump --config app.ini # use official command to back up needed file.
    exit
    scp /etc/gitea/gitea-dump-1716769046.zip root@server_B:~/ # maybe your file name is different with me, just use yours.
    exit
  3. Log in server B as root.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    apt update
    apt install unzip
    unzip gitea-dump-1716769046.zip
    mv app.ini /etc/gitea/app.ini
    rm -rf /var/lib/gitea/data # delete default file in new Gitea
    mv data /var/lib/gitea/
    mkdir /var/lib/gitea/data/gitea-repositories
    mv repos/* /var/lib/gitea/data/gitea-repositories/
    psql -U gitea -d giteadb < gitea-db.sql
    vim /etc/gitea/app.ini # edit the following infomation as yours.
    1
    2
    3
    4
    5
    [server]
    SSH_DOMAIN = gitea.your.domain
    DOMAIN = gitea.your.domain
    HTTP_PORT = 3000
    ROOT_URL = https://gitea.your.domain/
    1
    2
    chown -R git:git /etc/gitea/app.ini /var/lib/gitea
    service gitea restart
  4. Log into new Gitea and delete old ssh keys and re-add them as gitea dump won’t migrate your ssh keys. All done. Happy coding with your new Gitea!

Reference

  1. https://docs.gitea.com/zh-cn/administration/backup-and-restore
  2. https://github.com/go-gitea/gitea/issues/31093