surroundings
Operating system: centos7.6
openshift version: 3.11
gitlab mirror: gitlab-ce: 11.4.3-ce.0
Create pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gitlab-data-backup
namespace: gitlab
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 500Gi
Mount the backup directory
volumes:
.....
- name: volume-gitlab-backup
persistentVolumeClaim:
claimName: gitlab-data-backup
volumeMounts:
......
- mountPath: /var/opt/gitlab/backups
name: volume-gitlab-backup
Write backup script
vi /root/crontab/backup-gitlab.sh
The content is as follows (here deployed under the project gitlab), after obtaining the pod name, exec, and finally to be able to execute the
backup commandgitlab-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
Create backup scheduled tasks
crontab -e
30 23 * * 5 /root/crontab/backup-gitlab.sh >> /var/log/backup-gitlab.log 2>&1
Here is set to back up gitlab data at 11:30 every Friday
Write scripts for regular cleaning and backup data
vi /root/crontab/clear-backup-gitlab.sh
Delete the backup file 60 days ago
#!/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 {} \;
Create a scheduled task for cleaning backup data
crontab -e
00 23 * * 5 /root/crontab/clear-backup-gitlab.sh >> /var/log/clear-backup-gitlab.log 2>&1
Here is set to 11:00 every Friday to clean up the gitlab data that was backed up 60 days ago