gitlab备份修改配置文件和单个项目备份

2019-06-28  本文已影响0人  黑客不黑_

gitlab备份分为热备份和冷备份

一、备份全部

默认配置文件为/etc/gitlab/gitlab.rb
可是无论无何找不到这个文件,通过find命令搜索全盘找到不少gitlab.rb文件,可是都不是主配置文件。
后面在下面路径下找到了配置文件gitlab.yml。正好有修改服务器ip和配置所有配置的文件,当我看到那个服务器IP我就知道是这个配置文件了,那就是这个了。而且其他数据库、redis等配置文件都在这里。

[root@k8s-node2 etc]# pwd
/var/opt/gitlab/gitlab-rails/etc
[root@k8s-node2 etc]# ls
database.yml  gitlab_shell_secret  gitlab_workhorse_secret  gitlab.yml  rack_attack.rb  resque.yml  secrets.yml  unicorn.rb

再看下gitlab.yml文件,当/etc/gitlab/gitlab.rb文件,那么你的主配置文件肯定是在/var/opt/gitlab/gitlab-rails/etc/gitlab.yml 。
通过搜索backup就可以得到备份文件配置,更改path路径即可。

## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 172.16.3.42
    port: 80
    https: false

## Backup settings
  backup:
    path: "/home/data/gitlab"   # Relative paths are relative to Rails.root (default: tmp/backups/)
    archive_permissions:  # Permissions for the resulting backup.tar file (default: 0600)
    keep_time:    # default: 0 (forever) (in seconds)
    pg_schema:    # default: nil, it means that all schemas will be backed up
    upload:
      # Fog storage connection settings, see http://fog.io/storage/ .
      connection:
      # The remote 'directory' to store your backups. For S3, this would be the bucket name.
      remote_directory:
      multipart_chunk_size:
      encryption:
      storage_class:

同时给备份路径更改目录所有者为git账户,不然会报错。

cd /home/data/gitlab
chown git:root gitlab/
[root@k8s-node2 data]# ll
total 0
drwx--x--x 11 root root 135 May 16 17:11 docker
drwxr-xr-x  4 git  root 225 Jun 28 11:21 gitlab

可以备份了,备份命令为:

gitlab-rake gitlab:backup:create

备份完成就可以在备份路径下看到一个当前日期下的tar压缩文件,可以看到文件已经很大了。

[root@k8s-node2 gitlab]# pwd
/home/data/gitlab
[root@k8s-node2 gitlab]# ls
1561692095_2019_06_28_11.4.5_gitlab_backup.tar
[root@k8s-node2 gitlab]# du -h 1561692095_2019_06_28_11.4.5_gitlab_backup.tar 
13G 1561692095_2019_06_28_11.4.5_gitlab_backup.tar

编辑备份脚本

#!/bin/bash
/usr/bin/gitlab-rake gitlab:backup:create CRON=1

注意:环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出

# crontab -l
0 0,6,12,18 * * * /bin/bash -x /data/gitlab/backups/gitlab_backup.sh > /dev/null 2>&1

gitlan如何恢复呢?

gitlab-rake gitlab:backup:restore BACKUP=1561692095_2019_06_28_11.4.5

二、单个项目文件备份

进入gitlab,进入设置-->export project-->expand-->export project。


image.png image.png

下载得到tar.gz包。
如何导入:
新建项目,选择import project,选择gitlab export。


image.png

设置项目名选择文件导入导入项目即可。


image.png
上一篇 下一篇

猜你喜欢

热点阅读