liuming794 发表于 2018-1-10 16:35:38

Gitlab日常备份和恢复

  按照官方安装文档安装完成之后的/home/git目录结构如下,这里我大致翻译官方的内容,部分加上自己的话,英语功力捉急,请见谅
  |-- home
  | |-- git
  | |-- .ssh
  | |-- gitlab
  | |-- gitlab-satellites
  | |-- gitlab-shell
  | |-- repositories
  * `/home/git/.ssh` - ssh设定的目录. gitlab-shell管理着其中的 `authorized_keys`.
  * `/home/git/gitlab` - GitLab核心部分
  * `/home/git/gitlab-satellites` - 可以视为临时目录,通过web ui的提交请求文件以及检出版本库都会存放在这个位置
  * `/home/git/gitlab-shell` - gitlab的核心插件组件. 包括ssh协议克隆和其他一些功能.
  * `/home/git/repositories` - 原始版本库的所有项目组织的名称空间,也就是所有仓库的存储位置,所以这个目录里的数据非常重要,注意备份 **这是项目的关键数据. Keep a backup**
  *Note: gitlab-satellites 和 repositories的路径都被定义在gitlab中的 `config/gitlab.yml` 和 gitlab-shell.* 中的`config.yml`
  创建为所有版本库的存档,就是备份啦. 存储路径在gitlab中的 `config/gitlab.yml`
  文件命名 `_gitlab_backup.tar`.
  ```
  bundle exec rake gitlab:backup:create RAILS_ENV=production
  ```
  类似如下:
  ```
  Dumping database tables:
  - Dumping table events...
  - Dumping table issues...
  - Dumping table keys...
  - Dumping table merge_requests...
  - Dumping table milestones...
  - Dumping table namespaces...
  - Dumping table notes...
  - Dumping table projects...
  - Dumping table protected_branches...
  - Dumping table schema_migrations...
  - Dumping table services...
  - Dumping table snippets...
  - Dumping table taggings...
  - Dumping table tags...
  - Dumping table users...
  - Dumping table users_projects...
  - Dumping table web_hooks...
  - Dumping table wikis...
  Dumping repositories:
  - Dumping repository abcd...
  Creating backup archive: $TIMESTAMP_gitlab_backup.tar
  Deleting tmp directories...
  Deleting old backups...
  ```
  ### 利用备份文件恢复
  ```
  bundle exec rake gitlab:backup:restore RAILS_ENV=production
  ```
  选项:
  ```
  BACKUP=timestamp_of_backup (required if more than one backup exists)
  ```
  类似这样:
  ```
  Unpacking backup...
  Restoring database tables:
  -- create_table("events", {:force=>true})
  -> 0.2231s
[...]
  - Loading fixture events...
  - Loading fixture issues...
  - Loading fixture keys...
  - Loading fixture merge_requests...
  - Loading fixture milestones...
  - Loading fixture namespaces...
  - Loading fixture notes...
  - Loading fixture projects...
  - Loading fixture protected_branches...
  - Loading fixture schema_migrations...
  - Loading fixture services...
  - Loading fixture snippets...
  - Loading fixture taggings...
  - Loading fixture tags...
  - Loading fixture users...
  - Loading fixture users_projects...
  - Loading fixture web_hooks...
  - Loading fixture wikis...
  Restoring repositories:
  - Restoring repository abcd...
  Deleting tmp directories...
  ```
  ### 配置计划任务
  ```
  cd /home/git/gitlab
  sudo -u git -H editor config/gitlab.yml # 开启多久自动备份的时间
  sudo -u git crontab -e # git用户的计划任务
  ```
  增加如下的条目:
  ```
  # 每天凌晨2点进行一次全备份
  0 2 * * * cd /home/git/gitlab && PATH=/usr/local/bin:/usr/bin:/bin bundle exec rake gitlab:backup:create RAILS_ENV=production
  ```
页: [1]
查看完整版本: Gitlab日常备份和恢复