gitlab 备份与迁移

查看 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.rbgitlab-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
...

参考文档

【1】Gitlab备份、迁移、恢复和升级

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值