github私有仓库是收费的,有些代码不方便托管到外面的git仓库,因此就产生了自己搭建git服务器的需求。
好在有广大的开源人士的贡献,有了gitlab这一神器。
手动配置较多,直接用集成包: bitnami-gitlab-6.4.3-1-linux-x64-installer.run
=============================
假定gitlab安装路径为: /opt/gitlab-6.4.3-1/
全程以root用户操作。
1.设定备份目录:
/opt/gitlab-6.4.3-1/apps/gitlab/htdocs/config/gitlab.yml
2.备份:
有些时候会报错: You have already activated rake 0.9.2.2,but our Gemfile requires rake 10.1.0,Using bundle exec may solve this.
原因是默认的path路径不对,需要执行下bitnami自带的环境变量设置脚本: use_gitlab 即可解决。
cd /opt/gitlab-6.4.3-1/
./use_gitlab
cd /opt/gitlab-6.4.3-1/apps/gitlab/htdocs
bundle exec bin/rake gitlab:backup:create RAILS_ENV=production
3.恢复:
BACKUP=timestamp_of_backup #(required if more than one backup exists):
cd /opt/gitlab-6.4.3-1/
./use_gitlab
cd /opt/gitlab-6.4.3-1/apps/gitlab/htdocs
bundle exec bin/rake gitlab:backup:restore RAILS_ENV=production BACKUP=1405247282
chown git:git -R /opt/gitlab-6.4.3-1/apps/gitlab/repositories
4.crontab定时备份脚本参考:
use_gitlab使用了exec,脚本会重新打开一个进程,没有上下文,所以需要单独提出path.
脚本需要使用root账户运行。脚本包含了rsync远程同步到nas相应目录中,按照自己实际修改即可(预先生成ssh证书,免密码登录)。
#!/bin/bash if [ `id -u` -ne 0 ];then echo "this backup script must be exec as root." exit fi date PATH="/opt/gitlab-6.4.3-1/apps/gitlabci/gitlabci-runner/bin:/opt/gitlab-6.4.3-1/apps/gitlab/gitlab-shell/bin:/opt/gitlab-6.4.3-1/redis/bin:/opt/gitlab-6.4.3-1/sqlite/bin:/opt/gitlab-6.4.3-1/python/bin:/opt/gitlab-6.4.3-1/perl/bin:/opt/gitlab-6.4.3-1/git/bin:/opt/gitlab-6.4.3-1/ruby/bin:/opt/gitlab-6.4.3-1/mysql/bin:/opt/gitlab-6.4.3-1/apache2/bin:/opt/gitlab-6.4.3-1/common/bin:$PATH" echo "backup gitlab to local storage begin.. " cd /opt/gitlab-6.4.3-1/apps/gitlab/htdocs bundle exec bin/rake gitlab:backup:create RAILS_ENV=production echo "rsync -avzP --delete /data/backups_gitlab [email protected]:/mnt/disk1/docs/rsync_gitlab_backup" rsync -avzP --delete /data/backups_gitlab xxx@xxx.com:/mnt/disk1/docs/rsync_gitlab_backup/ date echo "this job is end."