查看 gitlab 版本
gitlab 备份与迁移只能在两个相同版本间进行。
# 查看gitlab 版本
root@server:~# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
16.9.0root@server:~#
进行备份
以下步骤在gitlab-ce 16.9.0
上实际验证过。
$ gitlab-rake gitlab:backup:create
# /etc/gitlab/gitlab.rb 配置文件须备份
# /var/opt/gitlab/nginx/conf nginx配置文件
# /etc/postfix/main.cfpostfix 邮件配置备份
备份缺省目录
缺省备份目录是 /var/opt/gitlab/backups
,如果要修改备份目录,编辑修改/etc/gitlab/gitlab.rb
### Backup Settings
###! Docs: https://docs.gitlab.com/omnibus/settings/backups.html
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/gitlab_backups"
# gitlab_rails['backup_gitaly_backup_path'] = "/opt/gitlab/embedded/bin/gitaly-backup"
###! Docs: https://docs.gitlab.com/ee/administration/backup_restore/backup_gitlab.html#backup-archive-permissions
gitlab_rails['backup_archive_permissions'] = 0644
# gitlab_rails['backup_pg_schema'] = 'public'
###! The duration in seconds to keep backups before they are allowed to be deleted
gitlab_rails['backup_keep_time'] = 604800
新的备份目录建议属性改为775
# chmod 775 gitlab_backups/
手工备份
gitlab.rb
和 gitlab-secrets.json
包含敏感信息,需要手工备份。
2024-09-27 15:30:11 +0800 -- Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
数据恢复
停止相关数据连接服务
root@server:/data/gitlab_backups# gitlab-ctl stop unicorn #停止相关数据连接服务
root@server:/data/gitlab_backups# gitlab-ctl stop sidekiq
修改backup文件权限
#修改权限,如果是从本服务器恢复可以不修改
root@server:/data/gitlab_backups# chmod 777 /data/gitlab_backups/1727422204_2024_09_27_16.9.0_gitlab_backup.tar
restore数据
注意恢复文件名不用带_gitlab_backup.tar
这一串后缀。
关于extension
的报错可以忽略。
root@server:/data/gitlab_backups# gitlab-rake gitlab:backup:restore BACKUP=1727422204_2024_09_27_16.9.0
2024-09-29 01:27:19 UTC -- Unpacking backup ...
2024-09-29 01:27:19 UTC -- Unpacking backup ... done
2024-09-29 01:27:19 UTC -- Restoring database ...
2024-09-29 01:27:19 UTC -- Be sure to stop Puma, Sidekiq, and any other process that
connects to the database before proceeding. For Omnibus
installs, see the following link for more information:
http://192.168.3.91/help/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installations
Before restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.
Do you want to continue (yes/no)? yes
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
2024-09-29 01:27:41 UTC -- Cleaning the database ...
2024-09-29 01:28:21 UTC -- done
Restoring PostgreSQL database gitlabhq_production ... ERROR: must be owner of extension pg_trgm
ERROR: must be owner of extension btree_gist
ERROR: must be owner of extension btree_gist
ERROR: must be owner of extension pg_trgm
查看 gitlab 网页端口
迁移后注意查看端口,缺省是80
,有的环境是8081
,注意用正确的网页端口访问。
# cd /var/opt/gitlab/nginx/conf
# vi gitlab-http.conf
---- site configuration(截取一部分) ----
server {
listen *:80; --修改端口
server_name localhost;
server_tokens off; ## Don't show the nginx version number, a security best practice
...