环境
操作系统:centos7.6
openshift版本: 3.11
gitlab镜像:gitlab-ce:11.4.3-ce.0
创建pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gitlab-data-backup
namespace: gitlab
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 500Gi
挂载备份目录
volumes:
.....
- name: volume-gitlab-backup
persistentVolumeClaim:
claimName: gitlab-data-backup
volumeMounts:
......
- mountPath: /var/opt/gitlab/backups
name: volume-gitlab-backup
编写备份脚本
vi /root/crontab/backup-gitlab.sh
内容如下(这里部署在项目gitlab下),获取pod名后 exec,最终是为了能执行
备份命令gitlab-rake gitlab:backup:create
#!/bin/bash
date
oc login -u xxxx -p xxxx url
oc exec -it `oc get po -n gitlab -l deploymentconfig=gitlab-ce --field-selector status.phase=Running | awk '{print $1}' | sed -n '2p'` -n gitlab gitlab-rake gitlab:backup:create
创建备份定时任务
crontab -e
30 23 * * 5 /root/crontab/backup-gitlab.sh >> /var/log/backup-gitlab.log 2>&1
这里设置为每周五11点30备份gitlab数据
编写定时清理备份数据脚本
vi /root/crontab/clear-backup-gitlab.sh
删除60天前的备份文件
#!/bin/bash
date
oc login -u xxxx -p xxxx url
oc exec -it `oc get po -n gitlab -l deploymentconfig=gitlab-ce --field-selector status.phase=Running | awk '{print $1}' | sed -n '2p'` -n gitlab -- find '/var/opt/gitlab/backups' -name '*.tar' -mtime +60 -exec rm {} \;
创建清理备份数据定时任务
crontab -e
00 23 * * 5 /root/crontab/clear-backup-gitlab.sh >> /var/log/clear-backup-gitlab.log 2>&1
这里设置为每周五11点00 清理60天前备份的gitlab数据