Gitlab备份与恢复

1,187次阅读
没有评论

共计 4131 个字符,预计需要花费 11 分钟才能阅读完成。

Gitlab备份与恢复

给Gitlab做下数据保障

无奈自建的服务总是要考虑这考虑那,嘎嘎埋埋,成本掂过67…..

事前准备

Gitlab备份与恢复

和部门人员嗦一句,准备停服了,靓仔们

创建本地备份目录

[root@ks-gitlab ~]# mkdir -p /var/opt/gitlab/backups && chown git.git /var/opt/gitlab/backups

配置Gitlab备份参数

# 编辑配置文件如下
[root@ks-gitlab ~]# vim /etc/gitlab/gitlab.rb

....略
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

###! Docs: https://docs.gitlab.com/ee/raketasks/backup_restore.html#backup-archive-permissions
gitlab_rails['backup_archive_permissions'] = 0644

gitlab_rails['backup_pg_schema'] = 'public'

###! The duration in seconds to keep backups before they are allowed to be deleted
gitlab_rails['backup_keep_time'] = 2592000
....略

编辑完后还需要重配置并重启

[root@ks-gitlab ~]# gitlab-ctl reconfigure

如果没有意外那就正常启动的(~ ̄▽ ̄)~

手动触发备份

[root@ks-gitlab ~]# cd /var/opt/gitlab/backups
[root@ks-gitlab backups]# gitlab-rake gitlab:backup:create
2020-10-21 17:48:09 +0800 -- Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2020-10-21 17:48:11 +0800 -- done
2020-10-21 17:48:11 +0800 -- Dumping repositories ...
 * docker/first-docker (@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b) ... [DONE]
[SKIPPED] Wiki
 * docker/docker-second (@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35) ... [DONE]
[SKIPPED] Wiki
2020-10-21 17:48:12 +0800 -- done
2020-10-21 17:48:12 +0800 -- Dumping uploads ... 
2020-10-21 17:48:12 +0800 -- done
2020-10-21 17:48:12 +0800 -- Dumping builds ... 
2020-10-21 17:48:12 +0800 -- done
2020-10-21 17:48:12 +0800 -- Dumping artifacts ... 
2020-10-21 17:48:12 +0800 -- done
2020-10-21 17:48:12 +0800 -- Dumping pages ... 
2020-10-21 17:48:12 +0800 -- done
2020-10-21 17:48:12 +0800 -- Dumping lfs objects ... 
2020-10-21 17:48:12 +0800 -- done
2020-10-21 17:48:12 +0800 -- Dumping container registry images ... 
2020-10-21 17:48:12 +0800 -- [DISABLED]
Creating backup archive: 1603273692_2020_10_21_13.2.9_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.

1.查看下备份文件

[root@ks-gitlab backups]# ll
总用量 440
-rw-r--r-- 1 git git 225280 10月 21 17:48 1603273692_2020_10_21_13.2.9_gitlab_backup.tar

2.整个定时任务自动备份

[root@ks-gitlab ~]# crontab -l
0 2 * * * root /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1

数据恢复

1.查看下有啥备份

[root@ks-gitlab ~]# ll /var/opt/gitlab/backups
总用量 252
-rw-r--r-- 1 git git 225280 10月 21 17:48 1603273692_2020_10_21_13.2.9_gitlab_backup.tar

2.停止相关服务

[root@ks-gitlab ~]# gitlab-ctl stop unicorn
[root@ks-gitlab ~]# gitlab-ctl stop sidekiq

3.使用备份恢复

# gitlab-rake gitlab:backup:restore BACKUP=编号

[root@ks-gitlab ~]# gitlab-rake gitlab:backup:restore BACKUP=1603273692_2020_10_21_13.2.9
....
....
输入yes
输入yes
....
[DONE]
2020-10-21 18:01:45 +0800 -- done
2020-10-21 18:01:45 +0800 -- Restoring repositories ...
 * docker/first-docker ... [DONE]
 * docker/docker-second ... [DONE]
2020-10-21 18:01:45 +0800 -- done
2020-10-21 18:01:45 +0800 -- Restoring uploads ... 
2020-10-21 18:01:45 +0800 -- done
2020-10-21 18:01:45 +0800 -- Restoring builds ... 
2020-10-21 18:01:45 +0800 -- done
2020-10-21 18:01:45 +0800 -- Restoring artifacts ... 
2020-10-21 18:01:45 +0800 -- done
2020-10-21 18:01:45 +0800 -- Restoring pages ... 
2020-10-21 18:01:45 +0800 -- done
2020-10-21 18:01:45 +0800 -- Restoring lfs objects ... 
2020-10-21 18:01:45 +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

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.

4.查看备份目录

[root@ks-gitlab ~]# ll /var/opt/gitlab/backups
总用量 252
-rw-r--r-- 1 git git 225280 10月 21 17:48 1603273692_2020_10_21_13.2.9_gitlab_backup.tar
-rw------- 1 git git    152 10月 21 17:48 artifacts.tar.gz
-rw-r--r-- 1 git git    190 10月 21 17:48 backup_information.yml
-rw------- 1 git git    152 10月 21 17:48 builds.tar.gz
drwxr-xr-x 2 git git     29 10月 21 17:48 db
-rw------- 1 git git    152 10月 21 17:48 lfs.tar.gz
-rw------- 1 git git    155 10月 21 17:48 pages.tar.gz
drwx------ 3 git git     21 10月 21 17:48 repositories
drwx------ 7 git git    131 10月 21 18:01 tmp
-rw------- 1 git git   9553 10月 21 17:48 uploads.tar.gz

5.启动服务

[root@ks-gitlab ~]# gitlab-ctl start sidekiq
ok: run: sidekiq: (pid 32468) 0s
[root@ks-gitlab ~]# gitlab-ctl start unicorn

6.验证备份

Gitlab备份与恢复

正文完
 
xadocker
版权声明:本站原创文章,由 xadocker 2020-10-23发表,共计4131字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)