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

相关推荐
cuijiecheng20181 天前
GitLab创建项目
gitlab
_运维那些事儿3 天前
GitLabCI/CD语法
linux·服务器·git·ci/cd·gitlab·运维开发·devops
_运维那些事儿3 天前
GitLab&Jenkins
运维·ci/cd·gitlab·jenkins·devops
Jeacean4 天前
gitlab 仓库所有分支开启分支保护脚本
gitlab
nhfc994 天前
Gitlab备份且提交Windows服务器数据
服务器·windows·gitlab
Knight_AL4 天前
Jenkins 配置 GitLab 认证并实现自动化部署
自动化·gitlab·jenkins
危笑ioi5 天前
docker部署jenkins/gitlab/nexus3/nginx配置端口转发与ssl
nginx·docker·gitlab·jenkins·ssl
木易 士心7 天前
GitLab 安装指南
git·gitlab
Linux运维技术栈7 天前
GitLab社区版备份优化:3M包为何是独立完整备份?
运维·git·gitlab
z.q.xiao8 天前
【镜像模式】WSL如何访问windows内网服务
linux·网络·windows·gitlab·wsl·dns