Gitlab+Jenkins学习之路(四)之gitlab备份和恢复

时间:2021-12-13 16:02:58
  • gitlab的备份和恢复

(1)创建备份目录,并授权

[root@linux-node1 ~]# mkdir /data/backups/gitlab -p
[root@linux-node1 ~]# chown -R git.git /data/
[root@linux-node1 ~]# ll /data/ -d
drwxr-xr-x git git Dec : /data/

(2)修改gitlab配置

[root@linux-node1 ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/data/backups/gitlab" #备份路径
gitlab_rails['backup_keep_time'] = #备份7天
[root@linux-node1 ~]# gitlab-ctl reconfigure
[root@linux-node1 ~]# gitlab-ctl restart
ok: run: gitaly: (pid ) 0s
ok: run: gitlab-monitor: (pid ) 1s
ok: run: gitlab-workhorse: (pid ) 0s
ok: run: logrotate: (pid ) 0s
ok: run: nginx: (pid ) 0s
ok: run: node-exporter: (pid ) 0s
ok: run: postgres-exporter: (pid ) 0s
ok: run: postgresql: (pid ) 0s
ok: run: prometheus: (pid ) 0s
ok: run: redis: (pid ) 0s
ok: run: redis-exporter: (pid ) 1s
ok: run: sidekiq: (pid ) 0s
ok: run: unicorn: (pid ) 0s

(3)备份

[root@linux-node1 ~]# gitlab-rake gitlab:backup:create
Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
* java/app1 ... [DONE]
* java/app1.wiki ... [SKIPPED]
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: 1513759548_2017_12_20_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. ( removed)

(4)查看备份目录

[root@linux-node1 ~]# ll /data/backups/gitlab/
total
-rw------- git git Dec : 1513759548_2017_12_20_10..4_gitlab_backup.tar
#1513759548_2017_12_20_10.2.4为时间戳,备份的时候用的着

(5)恢复备份

删除gitlab中的app1的项目,再恢复
停止数据写入服务:
[root@linux-node1 ~]# gitlab-ctl stop unicorn
[root@linux-node1 ~]# gitlab-ctl stop sidekiq

恢复数据:
[root@linux-node1 ~]# gitlab-rake gitlab:backup:restore BACKUP=1513759548_2017_12_20_10.2.4
[root@linux-node1 ~]# gitlab-ctl restart
ok: run: gitaly: (pid ) 0s
ok: run: gitlab-monitor: (pid ) 0s
ok: run: gitlab-workhorse: (pid ) 1s
ok: run: logrotate: (pid ) 0s
ok: run: nginx: (pid ) 1s
ok: run: node-exporter: (pid ) 0s
ok: run: postgres-exporter: (pid ) 1s
ok: run: postgresql: (pid ) 0s
ok: run: prometheus: (pid ) 1s
ok: run: redis: (pid ) 0s
ok: run: redis-exporter: (pid ) 1s
ok: run: sidekiq: (pid ) 0s
ok: run: unicorn: (pid ) 0s

Gitlab+Jenkins学习之路(四)之gitlab备份和恢复

此时即可恢复原来的项目

邮件配置:
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'xiaoming@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'] =
gitlab_rails['smtp_user_name'] = "xiaoming"
gitlab_rails['smtp_password'] = "your password"
gitlab_rails['smtp_domain'] = "126.com"
gitlab_rails['smtp_authentication'] = "login"