## 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
创建为所有版本库的存档,就是备份啦. 存储路径在gitlab中的 `config/gitlab.yml`
文件命名 `[TIMESTAMP]_gitlab_backup.tar`.
```
bundle exec rake gitlab:backup:create RAILS_ENV=production
```
类似如下:
```
Dumping database tables:
- Dumping table events... [DONE]
- Dumping table issues... [DONE]
- Dumping table keys... [DONE]
- Dumping table merge_requests... [DONE]
- Dumping table milestones... [DONE]
- Dumping table namespaces... [DONE]
- Dumping table notes... [DONE]
- Dumping table projects... [DONE]
- Dumping table protected_branches... [DONE]
- Dumping table schema_migrations... [DONE]
- Dumping table services... [DONE]
- Dumping table snippets... [DONE]
- Dumping table taggings... [DONE]
- Dumping table tags... [DONE]
- Dumping table users... [DONE]
- Dumping table users_projects... [DONE]
- Dumping table web_hooks... [DONE]
- Dumping table wikis... [DONE]
Dumping repositories:
- Dumping repository abcd... [DONE]
Creating backup archive: $TIMESTAMP_gitlab_backup.tar [DONE]
Deleting tmp directories...[DONE]
Deleting old backups... [SKIPPING]
```
### 利用备份文件恢复
```
bundle exec rake gitlab:backup:restore RAILS_ENV=production
```
选项:
```
BACKUP=timestamp_of_backup (required if more than one backup exists)
```
类似这样:
```
Dumping database ...
done
Dumping repositories ...
* ops/python_scripts ... [DONE]
* ops/python_scripts.wiki ... [SKIPPED]
* ops/umework ... [DONE]
* ops/umework.wiki ... [SKIPPED]
* ops/triaquae ... [DONE]
* ops/triaquae.wiki ... [SKIPPED]
done
Dumping uploads ...
done
Creating backup archive: 1395395250_gitlab_backup.tar ... done //创建成功了备份文件
Deleting tmp directories ... done
Deleting old backups ... done. (0 removed) //会删除旧的包
```
### 配置计划任务
```
cd /home/git/gitlab
sudo -u git -H editor config/gitlab.yml # 开启多久自动备份的时间
## Backup settings
backup:
path:"/opt/backup/" # Relative paths are relative to Rails.root (default: tmp/backups/) //路径
keep_time:86400 # default: 0 (forever) (in seconds) //自动备份时间
sudo -u git crontab -e # git用户的计划任务
```
增加如下的条目:
```
# 每天凌晨2点进行一次全备份
0 2 * * * cd /home/git/gitlab ;bundle exec rake gitlab:backup:create RAILS_ENV=production
```