Gitlab备份
备份时需要保持gitlab处于正常运行状态,直接执行gitlab-rake gitlab:backup:create
进行备份。
使用以上命令会在/var/opt/gitlab/backups
目录下创建一个名称类似为1530156812_2018_06_28_10.8.4_gitlab_backup.tar
的压缩包, 这个压缩包就是Gitlab整个的完整部分, 其中开头的1530156812_2018_06_28_10.8.4
是备份创建的日期。
/etc/gitlab/gitlab.rb
配置文件须备份/etc/gitlab/gitlab-scrects.json
密钥备份/var/opt/gitlab/nginx/conf nginx
配置文件
1.1 修改备份文件目录
可以通过/etc/gitlab/gitlab.rb
配置文件来修改默认存放备份文件的目录gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
修改完成之后使用gitlab-ctl reconfigure
命令重载配置文件即可
1.2 设置备份过期时间
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_keep_time'] = 604800 #以秒为单位
1.3 gitlab自动备份
创建定时任务
# 每天凌晨2点备份
[root@gitlab ~]# crontab -e
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
备份脚本
#!/bin/bash
#
# Filename: svnbak.sh
# Revision: 1.0
# Date: 2019/02/21
# Author: Scott
# Email: 79305495@qq.com
# Description: SVN完全备份
# Notes: 将脚本加入crontab中,每天定时执行
rm -f /var/opt/gitlab/backups/*.tar
/opt/gitlab/bin/gitlab-rake gitlab:backup:create
备份恢复
[root@gitlab ~]# scp /var/opt/gitlab/backups/1530156812_2018_06_28_10.8.4_gitlab_backup.tar root@10.0.0.6:/var/opt/gitlab/backups/
[root@gitlab ~]# gitlab-ctl stop unicorn #停止相关数据连接服务
[root@gitlab ~]# gitlab-ctl stop sidekiq
[root@gitlab-new ~]# chmod 777 /var/opt/gitlab/backups/1530156812_2018_06_28_10.8.4_gitlab_backup.tar
#修改权限,如果是从本服务器恢复可以不修改
[root@gitlab-new ~]# gitlab-rake gitlab:backup:restore BACKUP=1530156812_2018_06_28_10.8.4