在安装完gitlab server 后,备份是必不可少的。
常规备份
根据官方文档,我们只需要执行一个命令:
1
| $ sudo gitlab-rake gitlab:backup:create
|
就可以实现默认备份:
- 备份目录:
/var/opt/gitlab/backups
- 备份内容:
repo,uploads,builds,artifacts,pages,lfs objects,container register images
- 打成tar包
- 默认不删除以前的备份
对于一百多个仓库,备份花了一个多小时,大小8.5GB。还是挺慢的。
关于备份的配置
位于/etc/gitlab/gitlab.rb
的配置文件里有关于备份(Backup Settings)的配置. 也可以查看页面.
指定备份目录
1
| gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
|
保存日志时间
针对本地备份文件有效,默认7天(604800秒):
1
| gitlab_rails['backup_keep_time'] = 604800
|
跳过某些模块
默认所有都会备份:
1 2 3 4 5 6 7 8
| db (database) uploads (attachments) repositories (Git repositories data) builds (CI job output logs) artifacts (CI job artifacts) lfs (LFS objects) registry (Container Registry images) pages (Pages content)
|
可以跳过:
1
| sudo gitlab-rake gitlab:backup:create SKIP=db,uploads
|
定时备份
定时备份配置
每周日4点备份配置:
1 2
| sudo crontab -e -u root 0 4 * * 7 umask 0077; tar cfz /data/backups/$(date "+etc-gitlab-\%s.tgz") -C / etc/gitlab
|
恢复配置:
1 2
| sudo mv /etc/gitlab /etc/gitlab.$(date +%s) sudo tar -xf etc-gitlab-1399948539.tar -C /
|
定时备份数据
每天早上2点生成备份:
1 2 3
| sudo su - crontab -e 0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
|
CRON = 1环境设置告诉备份脚本在没有错误时禁止所有进度输出。建议使用此方法来减少cron垃圾邮件.
刷新配置生效
我们需要reconfig来生效配置:
1
| sudo gitlab-ctl reconfigure
|
恢复备份
TODO
默认备份日志输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| # gitlab-rake gitlab:backup:create 2019-06-12 14:50:02 +0800 -- Dumping database ... Dumping PostgreSQL database gitlabhq_production ... [DONE] 2019-06-12 14:50:08 +0800 -- done 2019-06-12 14:50:08 +0800 -- Dumping repositories ... * logger/log ... [SKIPPED] [SKIPPED] Wiki * yinjiaxin/suibian ... [SKIPPED] [SKIPPED] Wiki * yinjiaxin/learngit ... [DONE] [SKIPPED] Wiki * yuqin/yq ... [DONE] [SKIPPED] Wiki 。。。 。。。 2019-06-12 15:05:44 +0800 -- done 2019-06-12 15:05:44 +0800 -- Dumping uploads ... 2019-06-12 15:06:44 +0800 -- done 2019-06-12 15:06:44 +0800 -- Dumping builds ... 2019-06-12 15:06:47 +0800 -- done 2019-06-12 15:06:47 +0800 -- Dumping artifacts ... 2019-06-12 15:06:54 +0800 -- done 2019-06-12 15:06:54 +0800 -- Dumping pages ... 2019-06-12 15:06:57 +0800 -- done 2019-06-12 15:06:57 +0800 -- Dumping lfs objects ... 2019-06-12 15:07:00 +0800 -- done 2019-06-12 15:07:00 +0800 -- Dumping container registry images ... 2019-06-12 15:07:00 +0800 -- [DISABLED] Creating backup archive: 1560323223_2019_06_12_11.10.0-ee_gitlab_backup.tar ... done Uploading backup archive to remote storage ... skipped Deleting tmp directories ... done done done done Deleting old backups ... skipping
|