帅帅男孩 发表于 2018-1-11 08:57:09

持续集成(1)gitlab的安装

Gitlab 备份  

  
官网的备份说明
  

  
https:
//gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketasks/backup_restore.md  
查看备份设置
  

  
vim /home/git/gitlab/config/gitlab.yml
  

  
检查Backup Settings设置项
  
默认情况下,备份文件是存放在/home/git/gitlab/tmp/backups/
  
执行备份
  

  
sudo service gitlab stop # 先停止Gitlab,可以不暂停
  
cd /home/git/gitlab/
  
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
  

  
执行完成后,会在/home/git/gitlab/tmp/backups/目录下创建一个备份俄文件,以时间戳_gitlab_backup命名如 1417040627_gitlab_backup.tar
  
重新启动
  

  
sudo service gitlab start
  
sudo service nginx restart
  

  
还原
  

  
需要给其他用户配置读写执行的权限
  

  
chmod o+wrx /home/git/.ssh/authorized_keys.lock
  

  
否则会出现如下错误,是由于没有权限
  
/home/git/gitlab-shell/lib/gitlab_keys.rb:101:in `initialize’: Permission denied @ rb_sysopen - /home/git/.ssh/authorized_keys.lock (Errno::EACCES)
  

  
需要使用 git 用户来执行,否则会没有权限操作 git 目录下的文件,timestamp_of_backup为时间戳如 1417040627
  

  
sudo service gitlab stop
  
cd /home/git/gitlab/
  
sudo -u git -H bundle exec rake gitlab:backup:restore BACKUP=timestamp_of_backup RAILS_ENV=production
  

  
如果是从全新部署的 gitlab 还原,需要执行这一步
  

  
sudo -u git -H bundle exec rake gitlab:satellites:create RAILS_ENV=production
  

  
重启 gitlab
  

  
sudo service gitlab start
  
sudo service nginx restart
  

  
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
  

  
设置自动备份
  

  
sudo service gitlab stop;
  
cd /home/git/gitlab;
  
sudo -u git -H editor config/gitlab.yml;
  
# Enable keep_time in the backup section to automatically delete old backups
  

  
keep_time参数默认是604800(单位是秒),因此会保留最近7天内的备份
  

  
sudo -u git crontab -e # Edit the crontab for the git user
  

  
将如下内容添加到文件末尾
  

  
# Create a full backup of the GitLab repositories and SQL database every day at 2am
  
0 2 * * * cd /home/git/gitlab && PATH=/usr/local/bin:/usr/bin:/bin bundle exec rake gitlab:backup:create RAILS_ENV=production CRON=1
  

  
重新启动
  
sudo service gitlab start;
  
sudo service nginx restart;
  
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production;
  

  
要是忘记管理员密码的话:
  
参考:
  
https://www.nitrohsu.com/gitlab-reset-administrator-password.html
  
# Gitlab 安装路径
  
cd /home/git/gitlab
  
# 进入Rails控制台
  
sudo -u git -H bundle exec rails console production
  
进入控制台,如果知道需要修改用户的邮箱,使用如下,直接修改
  
user = User.find_by(email: 'admin@example.com')
  
user.password = 'secret_password'
  
user.password_confirmation = 'secret_password'
  
user.save
  
如果不知道具体邮箱,可以通过find来查找邮箱
  

  
user = User.find(1)
页: [1]
查看完整版本: 持续集成(1)gitlab的安装