1 - GitLab配置文件

GitLab默认的配置文件路径:/etc/gitlab/

  • /etc/gitlab/gitlab.rb:主配置文件,包含外部URL、仓库目录、备份目录等
  • /etc/gitlab/gitlab-secrets.json:(执行gitlab-ctl reconfigure命令行后生成),包含各类密钥的加密信息

手工备份/etc/gitlab/的所有文件:cp -R /etc/gitlab/ <backup-path>

2 - 备份指令

备份指令不会备份配置文件,需要手动备份配置目录和相关文件。

默认的备份目录为 /var/opt/gitlab/backups/

以下是/etc/gitlab/gitlab.rb文件中Backup Settings部分的内容

   379  ### Backup Settings
380 ###! Docs: https://docs.gitlab.com/omnibus/settings/backups.html
381
382 # gitlab_rails['manage_backup_path'] = true
383 # gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
384
385 ###! Docs: https://docs.gitlab.com/ee/raketasks/backup_restore.html#backup-archive-permissions
386 # gitlab_rails['backup_archive_permissions'] = 0644
387
388 # gitlab_rails['backup_pg_schema'] = 'public'
389
390 ###! The duration in seconds to keep backups before they are allowed to be deleted
391 # gitlab_rails['backup_keep_time'] = 604800
392
393 # gitlab_rails['backup_upload_connection'] = {
394 # 'provider' => 'AWS',
395 # 'region' => 'eu-west-1',
396 # 'aws_access_key_id' => 'AKIAKIAKI',
397 # 'aws_secret_access_key' => 'secret123'
398 # }
399 # gitlab_rails['backup_upload_remote_directory'] = 'my.s3.bucket'
400 # gitlab_rails['backup_multipart_chunk_size'] = 104857600
401
402 ###! **Turns on AWS Server-Side Encryption with Amazon S3-Managed Keys for
403 ###! backups**
404 # gitlab_rails['backup_encryption'] = 'AES256'
405 ###! The encryption key to use with AWS Server-Side Encryption.
406 ###! Setting this value will enable Server-Side Encryption with customer provided keys;
407 ###! otherwise S3-managed keys are used.
408 # gitlab_rails['backup_encryption_key'] = '<base64-encoded encryption key>'
409
410 ###! **Specifies Amazon S3 storage class to use for backups. Valid values
411 ###! include 'STANDARD', 'STANDARD_IA', and 'REDUCED_REDUNDANCY'**
412 # gitlab_rails['backup_storage_class'] = 'STANDARD'
413
414 ###! Skip parts of the backup. Comma separated.
415 ###! Docs: https://docs.gitlab.com/ee/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup
416 #gitlab_rails['env'] = {
417 # "SKIP" => "db,uploads,repositories,builds,artifacts,lfs,registry,pages"
418 #}

2.1 设置备份参数

[root@test102 ~]# vim /etc/gitlab/gitlab.rb
[root@test102 ~]# cat /etc/gitlab/gitlab.rb |grep -v "#" |grep -Ev '^$'
external_url 'http://192.168.16.102'
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" # 备份的目录
gitlab_rails['backup_archive_permissions'] = 0644 # 备份包(tar格式压缩包)的权限
gitlab_rails['backup_keep_time'] = 604800 # 备份的保留时间,单位是秒
unicorn['listen'] = '192.168.16.102'
unicorn['port'] = 8081
[root@test102 ~]# gitlab-ctl reconfigure # 重载配置,使之生效
......
......
......
Running handlers:
Running handlers complete
Chef Client finished, 9/730 resources updated in 46 seconds
gitlab Reconfigured!
[root@test102 ~]#

2.2 执行备份指令

[root@test102 ~]# ll /var/opt/gitlab/backups/
total 0
[root@test102 ~]# gitlab-rake gitlab:backup:create # 备份数据
2019-11-27 16:12:08 +0800 -- Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2019-11-27 16:12:10 +0800 -- done
2019-11-27 16:12:10 +0800 -- Dumping repositories ...
2019-11-27 16:12:10 +0800 -- done
2019-11-27 16:12:10 +0800 -- Dumping uploads ...
2019-11-27 16:12:10 +0800 -- done
2019-11-27 16:12:10 +0800 -- Dumping builds ...
2019-11-27 16:12:10 +0800 -- done
2019-11-27 16:12:10 +0800 -- Dumping artifacts ...
2019-11-27 16:12:10 +0800 -- done
2019-11-27 16:12:10 +0800 -- Dumping pages ...
2019-11-27 16:12:10 +0800 -- done
2019-11-27 16:12:10 +0800 -- Dumping lfs objects ...
2019-11-27 16:12:10 +0800 -- done
2019-11-27 16:12:10 +0800 -- Dumping container registry images ...
2019-11-27 16:12:10 +0800 -- [DISABLED]
Creating backup archive: 1574842330_2019_11_27_12.5.0_gitlab_backup.tar ... done
Uploading backup archive to remote storage ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... done. (0 removed)
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
Backup task is done.
[root@test102 ~]#
[root@test102 ~]# ll /var/opt/gitlab/backups/
total 172
-rw-r--r-- 1 git git 174080 Nov 27 16:12 1574842330_2019_11_27_12.5.0_gitlab_backup.tar
[root@test102 ~]#

3 - 定时备份

使用Crontab任务进行定时备份。

[root@test102 ~]# crontab -l
no crontab for root
[root@test102 ~]#
[root@test102 ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@test102 ~]#
[root@test102 ~]# crontab -l
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=10 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
[root@test102 ~]#

4 - 备份到云存储

从GitLab7.4开始,可以将备份文件上传到远端云存储上。

具体配置和操作,可查看官方文档:

涉及的配置项如下:
393 # gitlab_rails['backup_upload_connection'] = {
394 # 'provider' => 'AWS',
395 # 'region' => 'eu-west-1',
396 # 'aws_access_key_id' => 'AKIAKIAKI',
397 # 'aws_secret_access_key' => 'secret123'
398 # }
399 # gitlab_rails['backup_upload_remote_directory'] = 'my.s3.bucket'
400 # gitlab_rails['backup_multipart_chunk_size'] = 104857600

5 - 还原数据

特别注意:

  • 备份目录和gitlab.rb中定义的备份目录必须一致
  • GitLab的版本和备份文件中的版本必须一致,否则还原时会报错。
[root@test102 ~]# cat /etc/gitlab/gitlab.rb |grep "backup_path" |grep -Ev "^$"  # 确认备份目录
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
[root@test102 ~]#
[root@test102 ~]# ll /var/opt/gitlab/backups/ # 确认备份文件
total 172
-rw-r--r-- 1 git git 174080 Nov 27 16:12 1574842330_2019_11_27_12.5.0_gitlab_backup.tar
[root@test102 ~]#
[root@test102 ~]# gitlab-rake gitlab:backup:restore BACKUP=1574842330_2019_11_27_12.5.0 # 还原
Unpacking backup ... done
Before restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.

Do you want to continue (yes/no)? yes
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
2019-11-27 16:40:03 +0800 -- Cleaning the database ...
2019-11-27 16:40:05 +0800 -- done
2019-11-27 16:40:05 +0800 -- Restoring database ...
......
......
......
[DONE]
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring repositories ...
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring uploads ...
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring builds ...
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring artifacts ...
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring pages ...
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring lfs objects ...
2019-11-27 16:40:19 +0800 -- done
This task will now rebuild the authorized_keys file.
You will lose any data stored in the authorized_keys file.
Do you want to continue (yes/no)? yes

Deleting tmp directories ... done
done
done
done
done
done
done
done
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need to restore these files manually.
Restore task is done.
[root@test102 ~]#
[root@test102 ~]# gitlab-ctl restart # 重启服务
ok: run: alertmanager: (pid 26150) 1s
ok: run: gitaly: (pid 26163) 0s
ok: run: gitlab-exporter: (pid 26182) 1s
ok: run: gitlab-workhorse: (pid 26184) 0s
ok: run: grafana: (pid 26204) 1s
ok: run: logrotate: (pid 26216) 0s
ok: run: nginx: (pid 26223) 1s
ok: run: node-exporter: (pid 26229) 0s
ok: run: postgres-exporter: (pid 26235) 0s
ok: run: postgresql: (pid 26321) 1s
ok: run: prometheus: (pid 26330) 0s
ok: run: redis: (pid 26341) 1s
ok: run: redis-exporter: (pid 26345) 0s
ok: run: sidekiq: (pid 26353) 0s
ok: run: unicorn: (pid 26364) 0s
[root@test102 ~]#
[root@test102 ~]# gitlab-rake gitlab:check SANITZE=true # 检查GitLab所有组件是否运行正常
Checking GitLab subtasks ...

Checking GitLab Shell ...

GitLab Shell: ... GitLab Shell version >= 10.2.0 ? ... OK (10.2.0)
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Internal API available: OK
Redis available via internal API: OK
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

Sidekiq: ... Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab App ...

Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ... can't check, you have no projects
Redis version >= 2.8.0? ... yes
Ruby version >= 2.5.3 ? ... yes (2.6.3)
Git version >= 2.22.0 ? ... yes (2.22.0)
Git user has default SSH configuration? ... yes
Active users: ... 3
Is authorized keys file accessible? ... yes

Checking GitLab App ... Finished


Checking GitLab subtasks ... Finished

[root@test102 ~]#

GitLab - GitLab的备份与还原的更多相关文章

  1. gitlab 安装、备份与还原及常见设置

    gitlab 安装.备份与还原及常见设置 安装 安装过程比较简单,跑在 docker 上,执行命令即可 -v参数后面的值为卷的名称,自动创建数据卷(如果数据卷不存在) https://docs.git ...

  2. GitLab篇之备份还原

    1. GitLab备份配置 输入以下命令,打开gitlab配置文件 [root@code-server ~]# vim /etc/gitlab/gitlab.rb 修改以下配置,gitlab有自动清理 ...

  3. gitlab 本地 定时备份

    =============================================== 20171015_第1次修改                       ccb_warlock === ...

  4. Gitlab安装与备份恢复

    GitHub是2008年由Ruby on Rails编写而成,与业界闻名的Github类似;但要将代码上传到GitHub上面,而且将项目设为私有还要收费.GitLab是一个用于仓库管理系统的开源项目, ...

  5. Gitlab配置、备份、升级、迁移

    0.Gitlab安装 1.安装和配置必要的依赖关系 在CentOS7,下面的命令将在系统防火墙打开HTTP和SSH访问. yum install curl openssh-server postfix ...

  6. git学习------> Gitlab如何进行备份恢复与迁移?

    前段时间,在某台CenterOS服务器上搭建了Gitlab环境,并且大家陆陆续续的都把代码从svn迁移到了gitlab,但是之前的CenterOS服务器并不是搭建在公司的机房环境,而是搭建在办公室的某 ...

  7. 【linux】【gitlab】gitlab安装、备份、恢复、升级、内存消耗问题

    前言 GitLab:GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务.功能:Gitlab 是一个提供代码托管.提交审核和问题跟踪的代码管理平 ...

  8. GitLab安装及备份迁移数据

    centos7安装GitLab 下载相应版本rpm包 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/ 我此处下载9.3.6版本. # w ...

  9. Gitlab如何进行备份恢复与迁移?

    https://blog.csdn.net/ouyang_peng/article/details/77070977 1.Gitlab 创建备份 1.1 创建备份文件 首先我们得把老服务器上的Gitl ...

随机推荐

  1. Git的工作流程

    git的工作流程为: 克隆Git资源作为工作目录 在克隆的资源上添加或者修改文件 如果别人修改了,你可以更新资源 在提交前查看修改 提交修改 在修改完成后,如果发现错误,可以撤回提交并再次修改并提交 ...

  2. HDU3109: Worms(字符串变换类 DP)

    pro:开始有一个字母虫,然后字母虫在每一天可以选择自己身上的部分字母变换,变换规则形如A->BC. 现状给定最终字母虫的字符串,求最少用了多少天. 如有规则A->BC,B->AC, ...

  3. PHP——数组根据某一键值合并

    前言 其实要实现很简单直接foreach,再根据PHP中数组的特性就可以轻松实现. 步骤 这是源数据的格式 $info = [ [ "gname" => "特别关心 ...

  4. npm run build打包时修改的路径

  5. Spring Security 3多用户登录实现之二 多登录界面展示

    作者 接前讲,首先针对一个多种用户类型的登录需求,需要先实现多种用户类型的登录界面的展示,Spring Security提供了这样一个接口来帮助我们实现多种用户类型的登录界面的展示,这个接口就是Aut ...

  6. [Codeforces 1251F]Red-White Fence

    Description 题库链接 给你 \(n\) 块白木板,\(k\) 块红木板,分别有各自的长度 \(h_i\).让你用这些木板组成一段围栏,要满足: 只用一块红木板,且所有白木板的长度均严格小于 ...

  7. HDU-2196-Computer(树上DP)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=2196 题意: A school bought the first computer some time ...

  8. IDEA设置类注释和方法注释模板

    背景 在日常开发中,类和方法上希望有属于自己风格的注释模板,此文将记录如何设置IDEA类和方法注释模板. 注意:如果公司有统一的规范模板,请按照公司提供的规范模板去设置,这样可以统一代码注释风格.当然 ...

  9. .net core 多sdk 多版本 环境切换

    在讲述.net core多版本之前,我们先理解一下.net core sdk与.net core runtime之前的联系与区别,根据官网的解释我们可以简单地理解为:sdk是在开发过程中进行使用,而r ...

  10. MySQL 已有大数据量表进行分区踩坑

    一.背景mysql 表中已有 4 亿数据,为提高查询效率,需创建分区,一开始计划是创建 HASH 分区,结果报错:ERROR 1659 (HY000): Field 'partno' is of a ...