Gitlab的定时备份和恢复

gitlab定时备份

1、Gitlab的备份目录路径设置

[root@hdjr-centos-06 ~]# vim /etc/gitlab/gitlab.rb

在这里插入图片描述

2、在gitlab.rb配置文件中可以设置gitlab的备份文件路径、生成的备份文件权限、备份保留天数。

 228 # gitlab_rails['manage_backup_path'] = true                                       //开启备份功能
 229 # gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"            //备份文件路径
 232 # gitlab_rails['backup_archive_permissions'] = 0644                       //生成的备份文件权限
 235 # gitlab_rails['backup_keep_time'] = 604800                                      //备份保留天数

在这里插入图片描述

设置好之后保存退出。

3、重新生效gitlab配置

[root@hdjr-centos-06 opt]# gitlab-ctl reconfigure 

4、添加定时计划

[root@hdjr-centos-06 opt]# cd /opt
[root@hdjr-centos-06 opt]# crontab -e

5、添加定时任务

例如:

在每天的14:30、14:40、14:50备份数据

30 14 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
40 14 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
50 14 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

在这里插入图片描述

6、保存退出后,重启crontab。

 [root@hdjr-centos-06 opt]# systemctl restart crond

7、实现开机自启动

[root@hdjr-centos-06 opt]# systemctl enable crond

在这里插入图片描述


14:30的定时任务已经执行,备份已经生成。



gitlab项目的恢复

在这里插入图片描述

现在gitlab里有4个项目,现删除项目demoJar。

在这里插入图片描述

从备份文件中恢复gitlab

1、将备份文件权限修改为777,不然可能恢复的时候会出现权限不够,不能解压的问题

chmod 777 _gitlab_backup.tar

[root@hdjr-centos-06 backups]# chmod 777 1609396215_2020_12_31_12.3.5_gitlab_backup.tar

2、执行命令停止相关数据连接服务

[root@hdjr-centos-06 backups]# chmod 777 1609396215_2020_12_31_12.3.5_gitlab_backup.tar
[root@hdjr-centos-06 backups]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@hdjr-centos-06 backups]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
[root@hdjr-centos-06 backups]#

在这里插入图片描述

3、执行恢复

gitlab-rake gitlab:backup:restore BACKUP=1609396215_2020_12_31_12.3.5

在这里插入图片描述

[root@hdjr-centos-06 backups]# gitlab-rake gitlab:backup:restore BACKUP=1609396215_2020_12_31_12.3.5
Unpacking backup ... done
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

出现第一个交互页面,选择 yes


在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Gitlab的恢复操作会先将当前所有的数据清空,然后再根据备份数据进行恢复


出现第二个交互页面,选择 yes
在这里插入图片描述

4、最后再次启动Gitlab

[root@hdjr-centos-06 backups]# gitlab-ctl start

在这里插入图片描述

这时已经把数据恢复完成了,再次访问gitlab界面,发现demoJar项目已恢复。

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值