Centos7安装gitlab11 学习笔记之备份恢复及邮箱配置

一、备份

修改配置文件

vim /etc/gitlab/gitlab.rb

1 默认路径为
2 
3  333 # gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
4 
5 #可以自定义为“/data/backups/gitlab”
  gitlab_rails['backup_path'] = "/data/backups/gitlab"
7 gitlab_rails['backup_keep_time'] = 604800 #代表只保留7天

 

使之生效

[root@web1 ~]# mkdir -p /data/backups/gitlab
[root@web1 ~]# gitlab-ctl reconfigure

在重启以下

1 [root@web1 ~]# gitlab-ctl restart

 授权

[root@web1 backups]# chown -R git.git /data/backups/gitlab

加入定时任务

[root@web1 backups]# crontab -e 
 
 0 2 * * * /usr/bin/gitlab-rake gitlab:backup:create    #每天2点备份一次

手动测试,手动创建备份

[root@web1 backups]# /usr/bin/gitlab-rake gitlab:backup:create          
2019-05-16 23:32:25 +0800 -- Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2019-05-16 23:32:27 +0800 -- done
2019-05-16 23:32:27 +0800 -- Dumping repositories ...
 * proj1/test ... [DONE]
[SKIPPED] Wiki
2019-05-16 23:32:27 +0800 -- done
2019-05-16 23:32:27 +0800 -- Dumping uploads ... 
2019-05-16 23:32:27 +0800 -- done
2019-05-16 23:32:27 +0800 -- Dumping builds ... 
2019-05-16 23:32:27 +0800 -- done
2019-05-16 23:32:27 +0800 -- Dumping artifacts ... 
2019-05-16 23:32:27 +0800 -- done
2019-05-16 23:32:27 +0800 -- Dumping pages ... 
2019-05-16 23:32:28 +0800 -- done
2019-05-16 23:32:28 +0800 -- Dumping lfs objects ... 
2019-05-16 23:32:28 +0800 -- done
2019-05-16 23:32:28 +0800 -- Dumping container registry images ... 
2019-05-16 23:32:28 +0800 -- [DISABLED]
Creating backup archive: 1558020748_2019_05_16_11.10.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. (0 removed)
[root@web1 backups]# cd /data/backups/gitlab/
[root@web1 gitlab]# ll 
total 112
-rw------- 1 git git 112640 May 16  2019 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 12
drwxr-x--- 3 gitlab-prometheus root        42 May 16  2019 alertmanager
drwx------ 2 git               root         6 May  8 01:46 backups
-rw------- 1 root              root        38 May  8 01:49 bootstrapped
drwx------ 2 git               root        79 May 16 15:45 gitaly
drwx------ 3 git               root        26 May  8 01:46 git-data
drwxr-xr-x 3 git               root        20 May  8 01:46 gitlab-ci
drwxr-xr-x 2 git               root        32 May 16  2019 gitlab-monitor
drwxr-xr-x 9 git               root       160 May 16  2019 gitlab-rails
drwx------ 2 git               root        24 May 16  2019 gitlab-shell
drwxr-x--- 2 git               gitlab-www  54 May 16 15:45 gitlab-workhorse
drwx------ 3 root              root        71 May 16  2019 logrotate
drwxr-x--- 9 root              gitlab-www 163 May 16 15:45 nginx
drwxr-xr-x 3 root              root        32 May  8 01:49 node-exporter
drwx------ 2 gitlab-psql       root        26 May 16  2019 postgres-exporter
drwxr-xr-x 3 gitlab-psql       root        81 May 16 15:45 postgresql
drwxr-x--- 4 gitlab-prometheus root        53 May 16  2019 prometheus
-rw-r--r-- 1 root              root       226 May 16  2019 public_attributes.json
drwxr-x--- 2 gitlab-redis      git         60 May 16 15:50 redis
-rw-r--r-- 1 root              root        40 May  8 01:46 trusted-certs-directory-hash
[root@web1 gitlab]# cd git-data/
[root@web1 git-data]# ll 
total 0
drwxrws--- 4 git root 34 May 16 15:45 repositories
[root@web1 git-data]# cd repositories/
[root@web1 repositories]# ll 
total 0
drwx--S--- 3 git root 17 May 16 15:45 +gitaly
drwxr-s--- 3 git root 22 May 16 15:45 proj1
[root@web1 repositories]# cd proj1/
[root@web1 proj1]# ll 
total 0
drwxr-sr-x 7 git root 184 May 16 15:45 test.git
[root@web1 proj1]# 

 

四、邮件配置

添加如下配置即可

gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'zhangxingeng@126.com'
gitlab_rails['gitlab_email_display_name'] = 'gitlab'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.126.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "zhangxingeng"
gitlab_rails['smtp_password'] = "your_password"
gitlab_rails['smtp_domain'] = "126.com"
gitlab_rails['smtp_authentication'] = "login"

 

 

转载请注明出处:https://www.cnblogs.com/zhangxingeng/p/10874979.html 

posted @ 2019-05-16 15:58  乐章  阅读(753)  评论(0编辑  收藏  举报