一、备份
修改配置文件
vim /etc/gitlab/gitlab.rb
默认路径为 # gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" #可以自定义为“/data/backups/gitlab”
gitlab_rails['backup_path'] = "/data/backups/gitlab"
gitlab_rails['backup_keep_time'] = 604800 #代表只保留7天
使之生效
[root@web1 ~]# mkdir -p /data/backups/gitlab
[root@web1 ~]# gitlab-ctl reconfigure
在重启以下
[root@web1 ~]# gitlab-ctl restart
授权
[root@web1 backups]# chown -R git.git /data/backups/gitlab
加入定时任务
[root@web1 backups]# crontab -e
* * * /usr/bin/gitlab-rake gitlab:backup:create #每天2点备份一次
手动测试,手动创建备份
[root@web1 backups]# /usr/bin/gitlab-rake gitlab:backup:create
-- :: + -- Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
-- :: + -- done
-- :: + -- Dumping repositories ...
* proj1/test ... [DONE]
[SKIPPED] Wiki
-- :: + -- done
-- :: + -- Dumping uploads ...
-- :: + -- done
-- :: + -- Dumping builds ...
-- :: + -- done
-- :: + -- Dumping artifacts ...
-- :: + -- done
-- :: + -- Dumping pages ...
-- :: + -- done
-- :: + -- Dumping lfs objects ...
-- :: + -- done
-- :: + -- Dumping container registry images ...
-- :: + -- [DISABLED]
Creating backup archive: 1558020748_2019_05_16_11..4_gitlab_backup.tar ... done
Uploading backup archive to remote storage ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... done. ( removed)
[root@web1 backups]# cd /data/backups/gitlab/
[root@web1 gitlab]# ll
total
-rw------- git git May 1558020748_2019_05_16_11.10.4_gitlab_backup.tar
[root@web1 gitlab]# ### 1558020748_2019_05_16_11.10.4为事件戳,date -d 1558020748_2019_05_16_11.10.4
[root@web1 gitlab]# date -d @1558020748
Thu May 16 23:32:28 CST 2019
[root@web1 gitlab]#
###
二、恢复数据
首先删除项目,然后恢复测试
开始恢复
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:restore BACKUP=1558020748_2019_05_16_11.10.4
gitlab-ctl restart
三、只备份代码方法为
[root@web1 gitlab]# cd /var/opt/gitlab/
[root@web1 gitlab]# ll
total
drwxr-x--- gitlab-prometheus root May alertmanager
drwx------ git root May : backups
-rw------- root root May : bootstrapped
drwx------ git root May : gitaly
drwx------ git root May : git-data
drwxr-xr-x git root May : gitlab-ci
drwxr-xr-x git root May gitlab-monitor
drwxr-xr-x git root May gitlab-rails
drwx------ git root May gitlab-shell
drwxr-x--- git gitlab-www May : gitlab-workhorse
drwx------ root root May logrotate
drwxr-x--- root gitlab-www May : nginx
drwxr-xr-x root root May : node-exporter
drwx------ gitlab-psql root May postgres-exporter
drwxr-xr-x gitlab-psql root May : postgresql
drwxr-x--- gitlab-prometheus root May prometheus
-rw-r--r-- root root May public_attributes.json
drwxr-x--- gitlab-redis git May : redis
-rw-r--r-- root root May : trusted-certs-directory-hash
[root@web1 gitlab]# cd git-data/
[root@web1 git-data]# ll
total
drwxrws--- git root May : repositories
[root@web1 git-data]# cd repositories/
[root@web1 repositories]# ll
total
drwx--S--- git root May : +gitaly
drwxr-s--- git root May : proj1
[root@web1 repositories]# cd proj1/
[root@web1 proj1]# ll
total
drwxr-sr-x git root May : test.git
[root@web1 proj1]#
四、邮件配置
添加如下配置即可
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'
gitlab_rails['gitlab_email_display_name'] = 'gitlab'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.126.com"
gitlab_rails['smtp_port'] =
gitlab_rails['smtp_user_name'] = "zhangxingeng"
gitlab_rails['smtp_password'] = "your_password"
gitlab_rails['smtp_domain'] = "126.com"
gitlab_rails['smtp_authentication'] = "login"