GitLab备份
1、设置gitlab备份目录
vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/opt/gitlab_bak"
加载配置文件
gitlab-ctl reconfigure
2、创建备份
gitlab-rake gitlab:backup:create
2022-01-27 20:50:46 +0800 -- Dumping database ... Dumping PostgreSQL database gitlabhq_production ... [DONE] 2022-01-27 20:50:49 +0800 -- done 2022-01-27 20:50:49 +0800 -- Dumping repositories ... time="2022-01-27T12:50:49.848Z" level=info msg="started create" command=create gl_project_path=gitlab-instance-ac29792b.wiki relative_path=@groups/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35.wiki.git storage_name=default time="2022-01-27T12:50:49.853Z" level=warning msg="skipped create" command=create error="manager: repository empty: repository skipped" gl_project_path=gitlab-instance-ac29792b.wiki relative_path=@groups/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35.wiki.git storage_name=default time="2022-01-27T12:50:49.971Z" level=info msg="started create" command=create gl_project_path=gitlab-instance-ac29792b/Monitoring relative_path=@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.git storage_name=default time="2022-01-27T12:50:49.972Z" level=warning msg="skipped create" command=create error="manager: repository empty: repository skipped" gl_project_path=gitlab-instance-ac29792b/Monitoring relative_path=@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.git storage_name=default time="2022-01-27T12:50:49.989Z" level=info msg="started create" command=create gl_project_path=gitlab-instance-ac29792b/Monitoring.wiki relative_path=@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.wiki.git storage_name=default time="2022-01-27T12:50:49.989Z" level=warning msg="skipped create" command=create error="manager: repository empty: repository skipped" gl_project_path=gitlab-instance-ac29792b/Monitoring.wiki relative_path=@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.wiki.git storage_name=default time="2022-01-27T12:50:49.990Z" level=info msg="started create" command=create gl_project_path=gitlab-instance-ac29792b/Monitoring relative_path=@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.design.git storage_name=default time="2022-01-27T12:50:49.990Z" level=warning msg="skipped create" command=create error="manager: repository empty: repository skipped" gl_project_path=gitlab-instance-ac29792b/Monitoring relative_path=@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.design.git storage_name=default time="2022-01-27T12:50:49.990Z" level=info msg="started create" command=create gl_project_path=root/personal_git relative_path=@hashed/4b/22/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a.git storage_name=default time="2022-01-27T12:50:49.991Z" level=info msg="started create" command=create gl_project_path=root/personal_git.wiki relative_path=@hashed/4b/22/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a.wiki.git storage_name=default time="2022-01-27T12:50:49.994Z" level=warning msg="skipped create" command=create error="manager: repository empty: repository skipped" gl_project_path=root/personal_git.wiki relative_path=@hashed/4b/22/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a.wiki.git storage_name=default time="2022-01-27T12:50:49.994Z" level=info msg="started create" command=create gl_project_path=root/personal_git relative_path=@hashed/4b/22/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a.design.git storage_name=default time="2022-01-27T12:50:49.994Z" level=warning msg="skipped create" command=create error="manager: repository empty: repository skipped" gl_project_path=root/personal_git relative_path=@hashed/4b/22/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a.design.git storage_name=default time="2022-01-27T12:50:51.488Z" level=info msg="completed create" command=create gl_project_path=root/personal_git relative_path=@hashed/4b/22/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a.git storage_name=default 2022-01-27 20:50:51 +0800 -- done 2022-01-27 20:50:51 +0800 -- Dumping uploads ... 2022-01-27 20:50:51 +0800 -- done 2022-01-27 20:50:51 +0800 -- Dumping builds ... 2022-01-27 20:50:51 +0800 -- done 2022-01-27 20:50:51 +0800 -- Dumping artifacts ... 2022-01-27 20:50:51 +0800 -- done 2022-01-27 20:50:51 +0800 -- Dumping pages ... 2022-01-27 20:50:51 +0800 -- done 2022-01-27 20:50:51 +0800 -- Dumping lfs objects ... 2022-01-27 20:50:51 +0800 -- done 2022-01-27 20:50:51 +0800 -- Dumping container registry images ... 2022-01-27 20:50:51 +0800 -- [DISABLED] Creating backup archive: 1643287851_2022_01_27_14.6.3-ee_gitlab_backup.tar ... done Uploading backup archive to remote storage ... skipped Deleting tmp directories ... done done done done done done done done Deleting old backups ... skipping 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. Backup task is done.
查看备份文件
ll /opt/gitlab_bak
total 448436 -rw------- 1 git git 229591040 Jan 27 21:30 1643290228_2022_01_27_14.6.3-ee_gitlab_backup.tar
3、数据还原
注意:数据恢复时,gitlab的版本要与原备份的gitlab版本一致
停止数据连接服务
注意,不能执行gitlab-ctl stop,直接停掉gitlab服务,因为gitlab还原需要用到redis和postgresql连接
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
进行数据恢复
注意备份文件的权限,要设置为git:
chown -R git:git /opt/gitlab_bak/1654781429_2022_06_09_14.8.2-ee_gitlab_backup.tar
还原命令:
gitlab-rake gitlab:backup:restore BACKUP=1643895551_2022_02_03_14.6.3-ee 备份文件名称的前半部分
注意,通过这种方法将gitlab迁移到新主机上时,在修改项目信息或者删除项目时会报500错误:
这是由于前后的token不一致导致的,需要进入gitlab的数据库将token信息清除掉
进入gitlab数据库:适配14.8.2-ee版本,其他版本的命令可能不一致
gitlab-rails dbconsole --database main
执行以下命令,将token进行删除:
UPDATE projects SET runners_token = null, runners_token_encrypted = null;
UPDATE namespaces SET runners_token = null, runners_token_encrypted = null;
UPDATE application_settings SET runners_registration_token_encrypted = null;
刷新页面,500错误消失,修改成功