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项目已恢复。