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

相关推荐

  1. gitlab每日备份以及restore

    2024-07-09 17:44:10       27 阅读
  2. gitlab备份与恢复

    2024-07-09 17:44:10       33 阅读
  3. 【运维】Gitlab备份

    2024-07-09 17:44:10       28 阅读
  4. gitlab 备份和还原

    2024-07-09 17:44:10       25 阅读
  5. Elasticsearch的Snapshot and Restore(快照备份与恢复)

    2024-07-09 17:44:10       49 阅读
  6. MySQL每日备份

    2024-07-09 17:44:10       23 阅读
  7. GitLab备份与恢复测试(基于Docker)

    2024-07-09 17:44:10       55 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-09 17:44:10       50 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-09 17:44:10       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-09 17:44:10       43 阅读
  4. Python语言-面向对象

    2024-07-09 17:44:10       54 阅读

热门阅读

  1. Centos安装Node.js

    2024-07-09 17:44:10       42 阅读
  2. C#多线程并行计算实例

    2024-07-09 17:44:10       16 阅读
  3. C#架构师的成长之路

    2024-07-09 17:44:10       25 阅读
  4. 算法刷题1-10大排序算法汇总

    2024-07-09 17:44:10       26 阅读
  5. 设计模式——工厂模式

    2024-07-09 17:44:10       44 阅读
  6. c语言中printf函数参数个数可变实现原理

    2024-07-09 17:44:10       22 阅读
  7. FFmpeg——视频拼接总结

    2024-07-09 17:44:10       24 阅读