本文采用的是定时任务备份数据到本地服务器上。

修改配置文件

修改 /etc/gitlab/gitlab.rb 文件

  1. # 设置备份存储位置
  2. gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
  3. # 备份最近七天的数据,即 7*24*60*60 秒
  4. gitlab_rails['backup_keep_time'] = 604800

保存后,刷新配置文件

  1. gitlab-ctl reconfigure && gitlab-ctl restart

编辑定时任务

crontab -e
加入以下内容后保存

  1. #每天中午 12 点和傍晚 19 点自动执行备份操作#
  2. 0 12,19 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

重新启动定时器

  1. # 重启定时任务
  2. systemctl restart crond.service
  3. # 重装定时任务
  4. systemctl reload crond.service
  5. # 查看定时任务是否开启(可选)
  6. systemctl is-enabled crond.service
  7. # 查看所有用户下的定时任务(可选)
  8. cat /etc/passwd | cut -f 1 -d : |xargs -I {} crontab -l -u {}

至此,自动定时备份完成