Debian上GitLab数据库迁移步骤
sudo gitlab-rake gitlab:backup:create,默认备份文件存放在/var/opt/gitlab/backups/目录。cat /opt/gitlab/embedded/service/gitlab-rails/VERSION查看旧版本),避免版本不兼容导致迁移失败。gitlabhq_production数据库、gitlab用户)。迁移前需停止GitLab关键服务,确保数据一致性。执行以下命令:
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
sudo gitlab-ctl stop nginx
pg_dump工具导出数据库(若为MySQL,需替换为mysqldump)。命令:sudo -u postgres pg_dump -d gitlabhq_production > gitlab-backup.sql。scp将导出的SQL文件复制到新服务器指定目录(如/tmp)。命令:scp gitlab-backup.sql user@new-server-ip:/tmp。sudo -u postgres createdb gitlabhq_production;sudo -u postgres psql gitlabhq_production < /tmp/gitlab-backup.sql。/var/opt/gitlab/repositories,使用rsync同步到新服务器:sudo rsync -avz /var/opt/gitlab/repositories/ user@new-server-ip:/var/opt/gitlab/repositories/。/var/opt/gitlab/config)和附件目录(/var/opt/gitlab/shared),确保配置一致性:sudo rsync -avz /var/opt/gitlab/config/ user@new-server-ip:/var/opt/gitlab/config/;sudo rsync -avz /var/opt/gitlab/shared/ user@new-server-ip:/var/opt/gitlab/shared/。编辑新服务器的GitLab配置文件/etc/gitlab/gitlab.rb,更新数据库连接信息(若数据库仍在旧服务器,需修改为旧服务器IP;若已迁移至新服务器,保持localhost):
gitlab_rails['db_adapter'] = "postgresql"
gitlab_rails['db_host'] = "localhost" # 或旧服务器IP
gitlab_rails['db_port'] = 5432
gitlab_rails['db_username'] = "gitlab"
gitlab_rails['db_password'] = "your_password"
gitlab_rails['db_database'] = "gitlabhq_production"
同时检查gitlab_shell_ssh_port、gitlab_shell_ssh_host等配置是否符合新服务器环境。
sudo gitlab-ctl reconfigure,使配置文件变更生效。sudo gitlab-ctl start。sudo gitlab-ctl status,确保无报错。