GitLab备份

GitLab备份

配置备份信息

gitlab配置文件/etc/gitlab/gitlab.rb:

gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"      # 备份文件存放目录
gitlab_rails['backup_archive_permissions'] = 0644      # 备份文件权限
gitlab_rails['backup_keep_time'] = 604800      # 默认备份保留天数为7天(单位秒)

注意:如果备份目录不存在需要提前创建并授权gitlab访问

修改完配置文件后进行重载:

$ gitlab-ctl reconfigure

gitlab的备份

手动使用以下命令进行备份:

$ gitlab-rake gitlab:backup:create

输出如下内容:

...
2022-09-02 11:31:56 +0800 -- Dumping lfs objects ... 
2022-09-02 11:31:56 +0800 -- done
2022-09-02 11:31:56 +0800 -- Dumping terraform states ... 
2022-09-02 11:31:56 +0800 -- done
2022-09-02 11:31:56 +0800 -- Dumping container registry images ... 
2022-09-02 11:31:56 +0800 -- [DISABLED]
2022-09-02 11:31:56 +0800 -- Dumping packages ... 
2022-09-02 11:31:56 +0800 -- done
Creating backup archive: 1662089478_2022_09_02_14.9.3_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
done
done
Deleting old backups ... done. (2 removed)
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.

注意:输出最后有个警告,gitlab.rbgitlab-secrets.json两个文件中包含敏感数据,需要手动备份。

执行完后查看备份目录下的备份文件:

[root@master_host backups]# ll -h
总用量 5.2G
-rw-r--r-- 1 git git 5.2G 9月   2 11:32 1662089478_2022_09_02_14.9.3_gitlab_backup.tar

以上需要手动执行命令进行备份,可以依靠Jenkins或crontab进行每天定时备份;

gitlab备份恢复

注意:gitlab只能把备份还原到相同版本的gitlab上。

停止相关数据连接服务

$ gitlab-ctl stop unicorn
$ gitlab-ctl stop sidekiq
$ gitlab-ctl stop nginx

查看gitlab状态

$ gitlab-ctl status

通过之前的备份文件进行恢复

$ gitlab-rake gitlab:backup:restore BACKUP=/var/opt/gitlab/backups/1662089478_2022_09_02_14.9.3

注意:gitlab的恢复操作会先将当前所有的数据清空后,再根据备份数据进行回复。

如果是在其他机器上进行恢复,需要将gitlab.rbgitlab-secrets.json两个文件复制到相应目录下。

重新加载配置文件

$ gitlab-ctl reconfigure

重启gitlab

$ gitlab-ctl restart

查看gitlab 状态

$ gitlab-ctl status

检查恢复情况

$ gitlab-rake gitlab:check SANITIZE=true

恢复完成 。

posted @ 2022-09-02 14:04  忘川的彼岸  阅读(1427)  评论(0编辑  收藏  举报