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失败。

相关推荐
字节逆旅10 小时前
如何解决代码冲突
gitlab
林晓lx14 小时前
使用Git钩子+ husky + lint语法检查提高前端项目代码质量
前端·git·gitlab·源代码管理
爱宇阳18 小时前
从容器化到自动化:Vue3 项目 Docker 部署与 GitLab CI/CD 集成 Harbor 全流程
docker·自动化·gitlab
爱宇阳20 小时前
Spring Boot 项目 GitLab CI/CD 自动构建并推送到 Harbor 教程
spring boot·ci/cd·gitlab
爱宇阳1 天前
Vue3 项目 GitLab CI/CD 自动构建并推送到 Harbor 教程
ci/cd·gitlab
西部森林牧歌2 天前
Arbess零基础学习 - 使用Arbess+GitLab实现Node.js项目自动化构建/主机部署
ci/cd·node.js·gitlab·arbess·tiklab devops
极小狐3 天前
极狐GitLab 18.5 正式发布,更新 Maven 虚拟仓库 UI(Beta)、全新个人主页、实例级合规与安全策略管理 以及 DAST 认证脚本 等
java·gitlab·maven
维尔切4 天前
GitLab 版本控制系统
gitlab
创实信息4 天前
创实信息正式成为极狐GitLab中国授权代理
ci/cd·gitlab·devops·代码管理·极狐
谢尔登4 天前
【GitLab/CD】前端 CD
前端·gitlab