1. GitLab备份配置
输入以下命令,打开gitlab配置文件
[root@code-server ~]# vim /etc/gitlab/gitlab.rb
修改以下配置,gitlab有自动清理备份机制,所以我们只要配置上backup_keep_time就可以了
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" //gitlab备份目录 gitlab_rails['backup_keep_time'] = 604800 //备份保留天数为7天(即604800秒)
完成配置修改后,执行更新配置命令
root@code-server ~]# gitlab-ctl reconfigure
2. 备份命令
gitlab备份非常简单,一条命令就可以完整备份
gitlab-rake gitlab:backup:create
执行上面的命令后,就会在/var/opt/gitlab/backups路径下面生成一条类似1552496455_2019_03_14_11.8.0_gitlab_backup.tar的压缩包,这个压缩包就是完整的gitlab备份。其中1552496455_2019_03_14_11.8.0是备份创建的日期。
3. 定期自动备份
定期自动备份,需要使用crontab
命令,输入以下命令,生成或打开crontab文件
sudo crontab -e
输入定时备份命令,每天凌晨1点执行gitlab备份
0 1 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
在crontab文件里面,每一行代表一项任务,每行的每个字段代表一项设置,它的格式共分为六个字段,前五段是时间设定段,第六段是要执行的命令段,每个字段之间用空格分割,没用的段用*代替,格式如下:
m h dom mon dow user command
其中:
m: 表示分钟,可以是从0到59之间的任何整数。
h:表示小时,可以是从0到23之间的任何整数。
dom:表示日期,可以是从1到31之间的任何整数。
mon:表示月份,可以是从1到12之间的任何整数。
dow:表示星期几,可以是从0到7之间的任何整数,这里的0或7代表星期日。
user : 表示执行的用户。
command:要执行的命令,可以是系统命令,也可以是自己编写的脚本文件(如shell文件)
4. 还原
gitlab只能还原到与备份文件同版本的gitlab上
首先输入以下命令,停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
接下来开始还原操作,假设我们要还原的备份文件是1552496455_2019_03_14_11.8.0_gitlab_backup.tar
gitlab-rake gitlab:backup:restore BACKUP=1552496455_2019_03_14_11.8.0
完成还原后再次重启gitlab服务
gitlab-ctl start