数据备份:
首先要修改几个配置文件:
[root@VM-75-68 gitlab]# vim /etc/gitlab/gitlab.rb
gitlab_rails['manage_backup_path'] = true #打开备份路径
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" #自定义具体路径
gitlab_rails['backup_archive_permissions'] = 0644 #备份文件的权限
gitlab_rails['backup_keep_time'] = 7776000 #备份文件的保留时长, 7776000是90天
这里我们用的默认目录,如果配置其他目录的话,要手动创建,并:
chown -R git:git ***
chmod -R 777 ***
[root@VM-75-68 backups]# gitlab-ctl reconfigure
...
...
...
ok,现在我们手动备份看下:
[root@VM-75-68 backups]# gitlab-rake gitlab:backup:create
...
...
...
备份好之后,我们看下当前目录:
[root@VM-75-68 backups]# pwd
/var/opt/gitlab/backups
[root@VM-75-68 backups]# ll
total 28788
-rw-r--r--. 1 git git 29440000 Jul 24 04:07 1563912472_2019_07_24_11.1.4_gitlab_backup.tar
没问题,文件已经在了!
这里我们就能配合crontab做到每天备份gitlab库。
数据恢复:
如果不小心删除了某个项目或者分支,不要慌,我们来尝试恢复数据
首先关闭数据连接服务
[root@VM-75-68 backups]# gitlab-ctl stop unicorn
[root@VM-75-68 backups]# gitlab-ctl stop sidekiq
[root@VM-75-68 backups]# status
从状态中看到上面两个服务已经顺利关闭了,下面开始恢复操作:
[root@VM-75-68 backups]# gitlab-rake gitlab:backup:restore BACKUP=1563912472_2019_07_24_11.1.4
...
...
...
...
因为恢复操作会先将当前的数据库清空,然后再根据备份进行恢复,中间他会让你输入一个 ‘yes’
但是结尾出来了这个:
ALTER TABLE
ALTER TABLE
WARNING: no privileges were granted for "public"
GRANT
[DONE]
done
Restoring repositories ...
* root/test ... [DONE]
done
Restoring uploads ...
gtar: .: Cannot mkdir: No such file or directory
gtar: Exiting with failure status due to previous errors
rake aborted!
Backup::Error: Backup failed
???
回复失败了?
我们尝试把gitlab的进程开起来
[root@VM-75-68 backups]# gitlab-ctl start
[root@VM-75-68 backups]# gitlab-ctl status
发现都已经起来了,好的,执行检查操作:
[root@VM-75-68 backups]# gitlab-rake gitlab:check SANITIZE=true
Checking GitLab Shell ...
GitLab Shell version >= 7.1.4 ? ... OK (7.1.4)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
1/1 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: FAILED: Failed to connect to internal API
gitlab-shell self-check failed
Try fixing it:
Make sure GitLab is running;
Check the gitlab-shell configuration file:
sudo -u git -H editor /opt/gitlab/embedded/service/gitlab-shell/config.yml
Please fix the error above and rerun the checks.
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Reply by email is disabled in config/gitlab.yml
Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
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? ... skipped (no tmp uploads folder yet)
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: ...
1/1 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.5 ? ... yes (2.4.4)
Git version >= 2.9.5 ? ... yes (2.17.1)
Git user has default SSH configuration? ... yes
Active users: ... 2
Checking GitLab ... Finished
没看出什么问题,我们尝试访问页面:
502报错!!!???
原因是redis等程序还没启动,稍等下就好了,怀着忐忑的心情,等待了一分钟,刷新页面,好了!
项目也出来了!里面文件也对的!
网上查了下,这个报错可能是内部bug!没关系,主要数据出来了咱们就放心了!
以上,共勉!