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 Settings380  ###! Docs: https://docs.gitlab.com/omnibus/settings/backups.html381  382  # gitlab_rails['manage_backup_path'] = true383  # gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"384  385  ###! Docs: https://docs.gitlab.com/ee/raketasks/backup_restore.html#backup-archive-permissions386  # gitlab_rails['backup_archive_permissions'] = 0644387  388  # gitlab_rails['backup_pg_schema'] = 'public'389  390  ###! The duration in seconds to keep backups before they are allowed to be deleted391  # gitlab_rails['backup_keep_time'] = 604800392  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'] = 104857600401  402  ###! **Turns on AWS Server-Side Encryption with Amazon S3-Managed Keys for403  ###!   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 values411  ###!   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-backup416  #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)? yesDeleting 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 successfulChecking GitLab Shell ... FinishedChecking Gitaly ...Gitaly: ... default ... OKChecking Gitaly ... FinishedChecking Sidekiq ...Sidekiq: ... Running? ... yes
Number of Sidekiq processes ... 1Checking Sidekiq ... FinishedChecking Incoming Email ...Incoming Email: ... Reply by email is disabled in config/gitlab.ymlChecking Incoming Email ... FinishedChecking LDAP ...LDAP: ... LDAP is disabled in config/gitlab.ymlChecking LDAP ... FinishedChecking 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? ... yesChecking GitLab App ... FinishedChecking GitLab subtasks ... Finished[root@test102 ~]#

参考链接:https://www.cnblogs.com/anliven/p/11954964.html

gitlab备份与还原:配置文件解读、定时备份、云备份相关推荐

  1. 实验 3:备份和还原配置文件

    交换机备份TFTP Loading "flash:/c2960-lanbase-mz.122-25.FX.bin"... ######################### [OK ...

  2. 计算机系统的备份与还原实验报告,数据库《数据备份与还原》实验报告.doc

    <数据库<数据备份与还原>实验报告.doc>由会员分享,提供在线免费全文阅读可下载,此文档格式为doc,更多相关<数据库<数据备份与还原>实验报告.doc&g ...

  3. 利用360安全卫士里的【系统备份与还原】小工具进行系统备份与还原

    如题. 打开该工具, 备份位置不要放到C盘里. 备份完成后,会在开机选项里多一个菜单.该工具应该是把C盘完全备份了,还原时会格式化C盘.

  4. 微信备份到云服务器失败怎么回事,iCloud云备份失败是为什么呢?iCloud云备份启用失败如何解决...

    许多果粉们在使用iCloud的进行备份手机数据的时候都遇到过:iCloud云备份失败,启用"iCloud云备份"时发生问题这样的提示.那么,iCloud云备份失败是怎么样发生的,又 ...

  5. 计算机系统的备份与还原实验报告,实验报告系统备份和恢复.doc

    实验报告系统备份和恢复 电脑选购与维护·实验报告4 实验项目:系统备份与恢复 实验时间:2011年5月26日9-11节 星期:四 学号*****姓名晶Yui成绩根据实训操作情况填空. 本机安装操作系统 ...

  6. 轻松备份和还原Firefox配置文件

    Transferring a Firefox profile from one computer to another can be a pain if you have to do it manua ...

  7. Windows 7备份、还原功能详解

    备份.还原从来都是系统中的关键组件.在Vista中,系统备份.还原功能得到了加强.那么,在Windows 7中提供了什么样的备份.还原方案呢?本文将就这一方面和大家进行一番体验. 1.使用系统还原轻松 ...

  8. Java数据库篇9——备份与还原、忘记密码

    Java数据库篇9--备份与还原.忘记密码 1.备份 备份的应用场景 在服务器进行数据传输.数据存储和数据交换,就有可能产生数据故障.比如发生 意外停机或存储介质损坏. 这时,如果没有采取数据备份和数 ...

  9. MySql笔记之数据备份与还原

    MySQL数据备份.还原与迁移 一.数据备份------mysqldump 1.语法: mysqldump -u user(用户名)-h host(登录用户的主机名称)-p password(登录密码 ...

  10. mysql备份数据库怎么还原数据库文件_mysql如何备份和还原数据库文件

    MySQL使用命令备份和还原数据库 这篇文章主要介绍了MySQL使用命令备份和还原数据库,本文使用Mysql内置命令实现备份和还原,比较简单,需要的朋友可以参考下 数据库在使用当中都会有数据库备份工作 ...

最新文章

  1. ipad编程软件python-iPad可用的软件编程软件有吗?
  2. 键盘控制事件应用教程大全
  3. AI模型变身文豪:“看懂”新闻报道,命名图片更有文采
  4. C语言试题三十三之比较两个字符串的长度,(不得调用c语言提供的求字符串长度的函数),函数返回较长的字符串。若两个字符串长度相同,则返回第一个字符串。
  5. Windows系统下彻底卸载MySQL数据库
  6. 前端开发常用正则表达式
  7. 在工程中最常用的 vim使用技巧
  8. python判断是不是整数1002python判断是不是整数_Python判断一个数是不是为整数的方法...
  9. urllib2的Post和Get请求
  10. python实现TCP远程服务器文件上传,下载系统
  11. dataset的去重计数 g2_AntV 架构演进-G2 篇
  12. php 中 sql 查询语句怎么写,sql查询语句有哪些
  13. NameError: name ‘List‘ is not defined
  14. LinkedList线程安全问题
  15. MySQL 大表优化方案(长文)
  16. 分子动力学模拟学习2-Gromacs运行分子动力学模拟
  17. Matlab: 汉字转拼音函数包
  18. MAC创建文件夹 Permission denied
  19. Because an app is obscuring a permission request, Settings can't verify your response
  20. 在idea中如何导入一个已有的项目

热门文章

  1. python stringvar函数_Tkinter 求助,怎么获取StringVar() 的值
  2. alert点击完确定关闭浏览器窗口_关务实操技巧:单一窗口缓存4大清理方法,解决部分退单问题...
  3. Java基础day8
  4. python3的3D实战-基于panda3d(2)
  5. go语言基础到提高(10)- 包及方法
  6. 【NLP】darmatch: 一个非常高效的多模式字符串匹配工具
  7. 【机器学习】降维代码练习
  8. 【深度学习】总有些哪些大胆又新奇的卷积网络结构设计
  9. GPU算力免费用?百度AI Studio两周年惊喜活动开启
  10. 利用Docker/Ansible实现轻量集群服务部署(视频演示+彩蛋)