gitlab每日备份以及restore

gitlab服务有非常简洁的每日备份命令,

从production的gitlab的每日备份中restore到backup环境也非常方便。

一、Production gitlab每日备份

1. Production gitlab环境上编写脚本

复制代码
cat /root/gitlab_bak.sh

gitlab-rake gitlab:backup:create  >  /var/opt/gitlab/backups/log/$(date +"%Y-%m-%d-%H:%M:%S").log

运行这个脚本,会生成tar包到gitlab配置文件中指定的backup路径。

gitlab配置文件(/etc/gitlab/gitlab.rb)中配置backup路径的部分如下:(默认路径为/var/opt/gitlab/backups)

复制代码
### Backup Settings
###! Docs: https://docs.gitlab.com/omnibus/settings/backups.html

# gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

​

2. 创建定时任务进行每日备份

复制代码
0 2 * * * /root/gitlab_bak.sh

二、Backup的gitlab从每日备份中restore

1. Backup gitlab环境上创建脚本

restore脚本如下:

复制代码
cat gitlab_restore.sh

#!/bin/bash

backup_file=$(ls -t /var/opt/gitlab/backups/*.tar|head -1)
restore_path=/var/opt/gitlab/backups
echo "$(date "+%Y-%m-%d %H:%M:%S") Start restoring from backup file: $backup_file"

# stop db related services
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

# prepare the backupfiles to restore path
rm -rf ${restore_path}/*
cp ${backup_file} ${restore_path}/
chmod 777 -R ${restore_path}/*

gitlab-rake gitlab:backup:restore force=yes

gitlab-ctl reconfigure && gitlab-ctl restart

rm -rf ${restore_path}/*

echo "$(date "+%Y-%m-%d %H:%M:%S") End restoring, backup gitlab url: http://xxx"

需要把production备份的/var/opt/gitlab/backups/*.tar 拷贝到backup环境。

2. 运行脚本即可完成restore

注:

注意定期清理路径:/var/opt/gitlab/git-data/repositories/+gitaly/tmp

这个路径会占比较大的空间。可能会导致空间不足,restore失败。

相关推荐
染夕陌木7 小时前
极简教程:GitLab 上配置 SSH Key(附常见问题解决)
运维·ssh·gitlab
晨旭缘1 天前
GitLab CICD 中 K8s 部署:BOM 头与 YAML 格式全解
容器·kubernetes·gitlab
鳄鱼杆2 天前
服务器 | 2026年Ubuntu 24.04下GitLab Docker 企业级部署
服务器·ubuntu·gitlab
FreeBuf_3 天前
黑客滥用 GitHub 和 GitLab 托管恶意软件并实施凭证钓鱼攻击
gitlab·github
有理想的打工人6 天前
gitlab的参数设置与团队管理
gitlab
有理想的打工人6 天前
gitlab群组管理与ssh链接
ssh·gitlab
M-Ellen6 天前
从零搭建 Windows + WSL2 + Docker + GitLab CI/CD 完整手册
ci/cd·docker·gitlab
大脸胖柴7 天前
webStorm+gitLab操作学习
学习·gitlab·webstorm
jekc8688 天前
Ubuntu-GitLab
服务器·ubuntu·gitlab
在路上走着走着9 天前
openclaw v2026.4.5 版本 提示 pairing required 解决方案
gitlab