对gitlab进行备份将会创建一个包含所有库和附件的归档文件。对备份的恢复只能恢复到与备份时的gitlab相同的版本。将gitlab迁移到另一台服务器上的最佳方法就是通过备份和还原。

备份

gitlab提供了一个简单的命令行来备份整个gitlab,并且能灵活的满足需求。

备份时间戳

从gitlab 9.2版本开始,时间戳格式由EPOCH_YYYY_MM_DD更改为EPOCH_YYYY_MM_DD_Gitlab-version。

备份文件将保存在gitlab.yml文件中定义的backup_path中,文件名为TIMESTAMP_gitlab_backup.tar,TIMESTAMP为备份时的时间戳。

  1. 使用omnibus软件包安装的
sudo gitlab-rake gitlab:backup:create
1
sudo gitlab - rake gitlab : backup : create
  • 使用源码安装的
  • sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
    1
    sudo - u git - H bundle exec rake gitlab : backup : create RAILS_ENV = production
  • 在docker中运行的gitlab
  • docker exec -t <container name> gitlab-rake gitlab:backup:create
    1
    docker exec - t < container name > gitlab - rake gitlab : backup : create

    备份策略选项

    该选项对gitlab 8.17及以上版本有效。

    默认的备份策略是使用linux的tar/gzip命令。这在大多数情况下是没有问题的,但是当数据在打包过程中发生改变时,将会有错误抛出file changed as we read it,这会导致备份进程失败。

    位了解决这个问题,8.17引入了一个名为copy的备份策略,就是在调用tar、gzip时将数据拷贝到一个临时位置。不过也引入了另一个问题,将额外占用一倍的磁盘空间。

    要使用复制策略而不是默认流策略,可以指定STRATEGY = copy。例如,sudo gitlab-rake gitlab:backup:create STRATEGY = copy。

    排除特定目录

    可以通过加环境变量skip来选择要备份的内容。可用的选项有:

    • db (数据库)
    • uploads (附件)
    • repositories (Git repositories 数据)
    • builds (CI job output logs)
    • artifacts (CI job artifacts)
    • lfs (LFS objects)
    • registry (Container Registry images)
    • pages (Pages content)

    指定多个选项使用逗号分隔。

    omnibus版本安装

    sudo gitlab-rake gitlab:backup:create SKIP=db,uploads
    1
    sudo gitlab - rake gitlab : backup : create SKIP = db , uploads

    源码安装

    sudo -u git -H bundle exec rake gitlab:backup:create SKIP=db,uploads RAILS_ENV=production
    1
    sudo - u git - H bundle exec rake gitlab : backup : create SKIP = db , uploads RAILS_ENV = production

    备份文件上传到云

    这里就不介绍了,支持aws、google、openstack swift和rackspace。

    上传到本地挂载目录

    omnibus版本

    gitlab_rails['backup_upload_connection'] = { :provider => 'Local', :local_root => '/mnt/backups' }

    The directory inside the mounted folder to copy backups to

    Use ‘.’ to store them in the root directory

    gitlab_rails[‘backup_upload_remote_directory’] = ‘gitlab_backups’

    1
    2
    3
    4
    5
    6
    7
    8

    gitlab_rails [ 'backup_upload_connection' ] = {
    : provider = > 'Local' ,
    : local_root = > '/mnt/backups'
    }
    # The directory inside the mounted folder to copy backups to
    # Use '.' to store them in the root directory
    gitlab_rails [ 'backup_upload_remote_directory' ] = 'gitlab_backups'

    源码安装

    backup: # snip upload: # Fog storage connection settings, see http://fog.io/storage/ . connection: provider: Local local_root: '/mnt/backups' # The directory inside the mounted folder to copy backups to # Use '.' to store them in the root directory remote_directory: 'gitlab_backups'
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    backup :
    # snip
    upload :
    # Fog storage connection settings, see http://fog.io/storage/ .
    connection :
    provider : Local
    local_root : '/mnt/backups'
    # The directory inside the mounted folder to copy backups to
    # Use '.' to store them in the root directory
    remote_directory : 'gitlab_backups'

    备份配置文件

    需要对/etc/gitlab/gitlab.rb 和 /etc/gitlab/gitlab-secrets.json(Omnibus), or /home/git/gitlab/config/secrets.yml (source)进行配置,来保存数据库加密秘钥。

    使用crontab定时备份

    omnibus版本

    0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
    1
    0 2 * * * / opt / gitlab / bin / gitlab - rake gitlab : backup : create CRON = 1

    源码安装

    # Create a full backup of the GitLab repositories and SQL database every day at 4am 0 4 * * * cd /home/git/gitlab && PATH=/usr/local/bin:/usr/bin:/bin bundle exec rake gitlab:backup:create RAILS_ENV=production CRON=1
    1
    2

    # Create a full backup of the GitLab repositories and SQL database every day at 4am
    0 4 * * * cd / home / git / gitlab && PATH = / usr / local / bin : / usr / bin : / bin bundle exec rake gitlab : backup : create RAILS_ENV = production CRON = 1

    环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出。

    建议将/etc/gitlab备份到安全的地方。如果要还原gitlab应用程序,还需要还原gitlab-secrets.json。如果没有,那么使用双重身份验证的GitLab用户将无法访问GitLab服务器,而存储在GitLab中的“安全变量”将被丢失。

    omnibus 的所有配置都存储在/etc/gitlab中,只需备份此目录。

    sudo sh -c 'umask 0077; tar -cf $(date "+etc-gitlab-%s.tar") /etc/gitlab'
    1
    sudo sh - c 'umask 0077; tar -cf $(date "+etc-gitlab-%s.tar")  /etc/gitlab'

    使用crontab

    0 2 * * *  umask 0077; tar cfz /secret/gitlab/backups/$(date "+etc-gitlab-\%s.tgz") /etc/gitlab
    1
    0 2 * * *   umask 0077 ; tar cfz / secret / gitlab / backups / $ ( date "+etc-gitlab-\%s.tgz" )    / etc / gitlab

    服务器的ssh主机密钥存储在/etc/ssh/目录中,如果必须执行完整的服务器还原,请确保备份和还原这些密钥,以避免中间人攻击的警告。

    恢复

    只能还原到与备份文件相同的gitlab版本。

    源码安装的

    sudo service gitlab stop bundle exec rake gitlab:backup:restore RAILS_ENV=production
    1
    2

    sudo service gitlab stop
    bundle exec rake gitlab : backup : restore RAILS_ENV = production

    omnibus版本:

    首先有安装与备份文件相同的gitlab。

    执行gitlab-ctl reconfigure

    如果gitlab没有运行,需执行gitlab-ctl start。

    确保备份文件位于gitlab_rails['backup_path']。

    sudo gitlab-ctl stop unicorn sudo gitlab-ctl stop sidekiq # Verify sudo gitlab-ctl status # This command will overwrite the contents of your GitLab database! sudo gitlab-rake gitlab:backup:restore BACKUP=1493107454_2017_04_25_9.1.0 sudo gitlab-ctl start sudo gitlab-rake gitlab:check SANITIZE=true
    1
    2
    3
    4
    5
    6
    7

    sudo gitlab - ctl stop unicorn
    sudo gitlab - ctl stop sidekiq
    # Verify
    sudo gitlab - ctl status # This command will overwrite the contents of your GitLab database!
    sudo gitlab - rake gitlab : backup : restore BACKUP = 1493107454_2017_04_25_9.1.0
    sudo gitlab - ctl start
    sudo gitlab - rake gitlab : check SANITIZE = true

    收 藏

gitlab 备份与恢复相关推荐

  1. Gitlab备份与恢复[七]

    标签(linux): git 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 备份 配置文件中加入 gitlab_rails['bakup_path']='/da ...

  2. gitlab备份与恢复操作整理

    首先设定备份目录 我设置的本地目录是/usr/backup vim /etc/gitlab/gitlab.rb gitlab_rails['backup_path'] = "/usr/bac ...

  3. 88.搭建git服务器 安装与使用gitlab gitlab备份与恢复

    2019独角兽企业重金招聘Python工程师标准>>> 22.13 搭建git服务器 22.14/22.15 安装gitlab 22.16 使用gitlab 22.17 gitlab ...

  4. gitlab备份与恢复

    目录 一.修改数据存储位置: 二.修改备份存储位置: 三.每日整体备份 四.备份保存30天 五.自动备份 六.备份恢复 七.备份文件的忽略 前面有提到CentOS 下搭建Gitlab+Gitlab-r ...

  5. Gitlab搭建及常用命令

    Git成员 Git:是一种版本控制系统,是一个命令,是一种工具. Gitlib:是用于实现Git功能的开发库. Github:是一个基于Git实现的在线代码托管仓库,包含一个网站界面,向互联网开放. ...

  6. Gti版本控制系统Github与Gitlab的使用

    目录 一.Git.Github.Gitlab 的区别 二:Git介绍 1.Git 与 SVN 区别 2.Git工作流程 三.git安装 1.yum安装 2.Windows 平台上安装 3.Mac 平台 ...

  7. gitlab安装, web界面, 复份与恢复

    gitlab安装 github是一个开放的代码管理平台,如果想只是一组人,一个群体私有使用需要收费: gitlab是一套软件,可自建在自己的服务器上,等于拥有了一个具有私有功能的github平台,可以 ...

  8. Git 版本控制器 Gitlab与Github(企业级总结)

    文章目录 一.版本控制系统/版本控制器 1.版本控制系统 2.Git与Svn介绍 (1)Git (2)Svn 二.Git 基本操作 1.创建仓库命令 2.提交与修改 3.提交日志 4.远程操作 三.G ...

  9. Linux中级实战部署一:企业级 CICD 持续集成交付发布---(git,github,gitlab)

    企业级 CI/CD 持续集成/交付/发布 一:git,github,gitlab的区别 Git是版本控制系统:Github是在线的基于Git的代码托管服务,GitHub同时提供付费账户和免费账户:Gi ...

最新文章

  1. [泰然翻译] cocos2d programming guide翻译(10)
  2. 在silverlight中通过对话框把选择的图片插入到RichTextBox中
  3. 微软家浏览器挺有意思,大家体会一下
  4. 判断手机所属三大运营商 移动、联通、电信
  5. bhjqahjshjhjgqwsoixcyuwyub
  6. 有效需求分析的基本流程
  7. 探索比特币源码3-熟悉RPC接口
  8. 专题导读:学术大数据
  9. 浅谈EventBus的使用原理
  10. 节日仪式感海报PSD分层模板,快来pick一下!
  11. 软考高级 真题 2017年上半年 信息系统项目管理师 案例分析
  12. 多渔:赚钱,就是专注和刻意练习!
  13. IEEE 2021年新增Fellow出炉,70余位华人入选
  14. 郁金香搜索引擎的方案(2017版)
  15. 植物大战僵尸用户存档修改(单机版)
  16. 信息架构的设计思路 .
  17. 自己写一个微型数据库_“最国际化的微型机构:”两名伦敦训练营的毕业生如何建造了一个远程…...
  18. 详细分析stm32f10x.h
  19. NIPS2022上的图神经网络相关论文总结
  20. 我又双叒叕赶来科普了

热门文章

  1. EXT4 之superblock 结构体剖析
  2. 虚拟机的破解root密码
  3. 2021年哔哩哔哩Java高级面试题及答案,知识点总结+面试题解析
  4. Vue中鼠标移入移出事件-解析
  5. Python3 单行注释,多行注释,文档注释的用法
  6. 笔记本借用服务器性能优秀强大,超强性能笔记本之工作站,非游戏用户看过来...
  7. Android 使用第三方软件PrinterShare实现USB 或WIFI 打印功能
  8. 没有社保对买商业保险有什么影响?
  9. win10系统可禁用的服务器,win10应该禁用哪些服务
  10. 计算机基础知识课件北京大板,计算机基础知识