This commit is contained in:
Nathan Rashleigh committed 2025-04-12 21:11:40 +10:00
1 parent 2b38528445
commit 8b0ef37ffa
5 files changed
+94 -129

No files matched your search

+60 -81
View File
@@ -1,88 +1,67 @@
---
# ---
apiVersion: v1
kind: PersistentVolume
metadata:
name: crates-postgres-backup-pv
spec:
storageClassName: ""
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
claimRef:
namespace: default
name: crates-postgres-backup-pvc
hostPath:
# Into homedir so we can scp it ez
path: "/home/ntr/archives/crates-postgres"
type: DirectoryOrCreate
# kind: PersistentVolumeClaim
# apiVersion: v1
# metadata:
# name: crates-postgres-backup-pvc
# spec:
# volumeName: crates-postgres-backup-pv
# accessModes:
# - ReadWriteOnce
# resources:
# requests:
# storage: 1Gi
---
# ---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: crates-postgres-backup-pvc
spec:
volumeName: crates-postgres-backup-pv
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
# apiVersion: batch/v1
# kind: CronJob
# metadata:
# name: crates-db-backup
# spec:
# schedule: "20 4 * * *"
# jobTemplate:
# spec:
# template:
# metadata:
# labels:
# app: crates-postgres-backup
# spec:
# restartPolicy: Never
# containers:
# - name: crates-postgres-backup
# image: postgres:16
# command:
# - "/bin/sh"
# - "-c"
# -
# |
# cd /mnt/dest/
# TZ="Australia/Melbourne"
# TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S')
# DEST=crates-$TIMESTAMP.sql.gz
---
# echo "Backing up to $DEST"
# pg_dump --dbname=$POSTGRES_URL | gzip > $DEST
# echo "Backup Complete"
apiVersion: batch/v1
kind: CronJob
metadata:
name: crates-db-backup
spec:
schedule: "20 4 * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app: crates-postgres-backup
spec:
restartPolicy: Never
containers:
- name: crates-postgres-backup
image: postgres:16
command:
- "/bin/sh"
- "-c"
-
|
cd /mnt/dest/
TZ="Australia/Melbourne"
TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S')
DEST=crates-$TIMESTAMP.sql.gz
# echo "Removing old copies..."
# find . -type f -name "*.sql.gz" -mtime 7 | xargs rm -v
echo "Backing up to $DEST"
pg_dump --dbname=$POSTGRES_URL | gzip > $DEST
echo "Backup Complete"
# echo "Setting latest link..."
# ln -nfs $DEST latest.sql.gz
# env:
# - name: POSTGRES_URL
# valueFrom:
# secretKeyRef:
# name: crates
# key: POSTGRES_URL
# volumeMounts:
# - name: crates-postgres-backup-storage
# mountPath: /mnt/dest
# volumes:
# - name: crates-postgres-backup-storage
# persistentVolumeClaim:
# claimName: crates-postgres-backup-pvc
echo "Removing old copies..."
find . -type f -name "*.sql.gz" -mtime 7 | xargs rm -v
echo "Setting latest link..."
ln -nfs $DEST latest.sql.gz
env:
- name: POSTGRES_URL
valueFrom:
secretKeyRef:
name: crates
key: POSTGRES_URL
volumeMounts:
- name: crates-postgres-backup-storage
mountPath: /mnt/dest
volumes:
- name: crates-postgres-backup-storage
persistentVolumeClaim:
claimName: crates-postgres-backup-pvc
---
# ---