borg offsite backup included so Maintenance actions (purge and compact)
This commit is contained in:
@@ -2,7 +2,36 @@
|
||||
|
||||
## borgbackup cockpit (companion scripts)
|
||||
|
||||
``` bash
|
||||
borg list ${BORG_REPO}
|
||||
borg list ${BORG_REPO}::gitea-data-2025-03-12_02:00:06
|
||||
Not in use anymore, the cron job already performs the following actions. Keeping it for now for notes purposes.
|
||||
|
||||
### list current backups
|
||||
|
||||
```bash
|
||||
POD_NAME=$(kubectl get pod -l app=borgbackup-cockpit -o jsonpath='{.items[0].metadata.name}')
|
||||
kubectl exec -it ${POD_NAME} -- borg list ${BORG_REPO}
|
||||
```
|
||||
|
||||
### purge backups
|
||||
|
||||
```bash
|
||||
POD_NAME=$(kubectl get pod -l app=borgbackup-cockpit -o jsonpath='{.items[0].metadata.name}')
|
||||
kubectl exec -it ${POD_NAME} -- bash -c "\
|
||||
borg prune -v --list --keep-daily=10 --keep-weekly=7 --keep-monthly=-1 ${BORG_REPO} --glob-archives='gitea-data*' && \
|
||||
borg prune -v --list --keep-daily=10 --keep-weekly=7 --keep-monthly=-1 ${BORG_REPO} --glob-archives='postgresql-export*'"
|
||||
```
|
||||
|
||||
### clean up space
|
||||
|
||||
```bash
|
||||
POD_NAME=$(kubectl get pod -l app=borgbackup-cockpit -o jsonpath='{.items[0].metadata.name}')
|
||||
kubectl exec -it ${POD_NAME} -- bash -c "\
|
||||
borg compact ${BORG_REPO} --verbose"
|
||||
```
|
||||
|
||||
### Get info
|
||||
|
||||
```bash
|
||||
POD_NAME=$(kubectl get pod -l app=borgbackup-cockpit -o jsonpath='{.items[0].metadata.name}')
|
||||
kubectl exec -it ${POD_NAME} -- bash -c "\
|
||||
borg info ${BORG_REPO} --json"
|
||||
```
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: borgbackup-cockpit
|
||||
namespace: git-limbosolutions-com
|
||||
labels:
|
||||
app: borgbackup-cockpit
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: borgbackup-cockpit
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: borgbackup-cockpit
|
||||
spec:
|
||||
containers:
|
||||
- name: borg-client
|
||||
image: git.limbosolutions.com/kb/borg-backup:latest
|
||||
resources:
|
||||
limits:
|
||||
memory: "512Mi"
|
||||
cpu: "500m"
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
cpu: "250m"
|
||||
env:
|
||||
- name: BORG_REPO
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: gitea-backup-secret
|
||||
key: BORG_REPO
|
||||
|
||||
- name: BORG_PASSPHRASE
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: gitea-backup-secret
|
||||
key: BORG_PASSPHRASE
|
||||
|
||||
- name: BORG_RSH
|
||||
value: ssh -o StrictHostKeyChecking=no
|
||||
|
||||
- name: BORG_KEY_FILE
|
||||
value: /root/.borg/key
|
||||
|
||||
command: ["sh", "-c"]
|
||||
args:
|
||||
- |
|
||||
while true; do
|
||||
sleep 1s
|
||||
done
|
||||
|
||||
volumeMounts:
|
||||
|
||||
- name: gitea-backup-secret
|
||||
mountPath: /root/.borg/key
|
||||
subPath: BORG_KEY_FILE
|
||||
|
||||
- name: gitea-backup-secret
|
||||
mountPath: /root/.ssh/id_rsa
|
||||
subPath: SSH_ID_RSA
|
||||
volumes:
|
||||
- name: gitea-backup-secret
|
||||
secret:
|
||||
secretName: gitea-backup-secret
|
||||
defaultMode: 0600
|
||||
|
||||
@@ -18,17 +18,11 @@ spec:
|
||||
command: ["sh", "-c"]
|
||||
args:
|
||||
- |
|
||||
#echo "INFO: Starting export"
|
||||
set -e
|
||||
. /root/.gitea-inline-config/database
|
||||
export PGPASSWORD=$PASSWD
|
||||
#echo "INFO: Exporting database"
|
||||
pg_dump -h gitea-postgresql.git-limbosolutions-com.svc.cluster.local -U $USER -d $NAME > /data/postgresql-export/db_backup.sql
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "ERROR: Exporting database failed"
|
||||
exit 1
|
||||
fi
|
||||
#echo "INFO: Exporting database finished"
|
||||
|
||||
|
||||
volumeMounts:
|
||||
|
||||
- name: backup-var-data
|
||||
@@ -71,24 +65,25 @@ spec:
|
||||
command: ["sh", "-c"]
|
||||
args:
|
||||
- |
|
||||
|
||||
set -e
|
||||
borg create ${BORG_REPO}::"postgresql-export-$(date +%Y-%m-%d_%H:%M:%S)" /data/postgresql-export
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "ERROR: Borg backup failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
borg create ${BORG_REPO}::"gitea-data-$(date +%Y-%m-%d_%H:%M:%S)" /data/gitea-data
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "ERROR: Borg backup failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#ssh to backup server and enforce rclone to onedrive
|
||||
|
||||
# ssh to backup server and enforce rclone to onedrive
|
||||
${BORG_RSH} mf@backupsrv01.dev.lan \
|
||||
"rclone sync ~/borg-repos/git.limbosolutions.com mf.onedrive:.backups/git.limbosolutions.com/borg" &&
|
||||
echo "INFO: Backup git.limbosolutions.com (offsite) finished"
|
||||
|
||||
#cleanup
|
||||
borg prune -v --list --keep-daily=10 --keep-weekly=7 --keep-monthly=-1 ${BORG_REPO} --glob-archives='gitea-data*'
|
||||
borg prune -v --list --keep-daily=10 --keep-weekly=7 --keep-monthly=-1 ${BORG_REPO} --glob-archives='postgresql-export*'
|
||||
borg compact ${BORG_REPO}
|
||||
|
||||
#outputs info
|
||||
borg info ${BORG_REPO}
|
||||
#borg info ${BORG_REPO} --json
|
||||
|
||||
volumeMounts:
|
||||
- name: gitea-data
|
||||
mountPath: /data/gitea-data
|
||||
|
||||
Reference in New Issue
Block a user