pg backup as well
This commit is contained in:
		
							
								
								
									
										37
									
								
								infrastructure/backup/postgres/cronjob.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								infrastructure/backup/postgres/cronjob.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| apiVersion: batch/v1 | ||||
| kind: CronJob | ||||
| metadata: | ||||
|   name: postgres-backup | ||||
| spec: | ||||
|   # Backup the database every day at 1AM | ||||
|   schedule: "0 1 * * *" | ||||
|   jobTemplate: | ||||
|     spec: | ||||
|       template: | ||||
|         spec: | ||||
|           containers: | ||||
|           - name: postgres-backup | ||||
|             image: postgres:15 | ||||
|             command: ["/bin/sh"] | ||||
|             args: | ||||
|               - "-c" | ||||
|               - >- | ||||
|                 echo "$postgress_password" > /root/.pgpass | ||||
|                 && | ||||
|                 chmod 600 /root/.pgpass | ||||
|                 && | ||||
|                 pg_dumpall -U postgres -h postgrespostgres-postgresql.postgres > /backup/backup-$(date +"%m-%d-%Y-%H-%M").sql | ||||
|             env: | ||||
|             - name: PGpostgress_passwordPASS | ||||
|               valueFrom: | ||||
|                 secretKeyRef: | ||||
|                   name: postgres-password | ||||
|                   key: password | ||||
|             volumeMounts: | ||||
|             - mountPath: /backup | ||||
|               name: postgres-backup-claim | ||||
|           restartPolicy: Never | ||||
|           volumes: | ||||
|           - name: postgres-backup-claim | ||||
|             persistentVolumeClaim: | ||||
|               claimName: postgres-backup-claim | ||||
							
								
								
									
										9
									
								
								infrastructure/backup/postgres/kustomization.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								infrastructure/backup/postgres/kustomization.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| apiVersion: kustomize.config.k8s.io/v1beta1 | ||||
| kind: Kustomization | ||||
|  | ||||
| namespace: backup | ||||
|  | ||||
| resources: | ||||
|   - postgres.sealedsecret.yaml | ||||
|   - pvc.yaml | ||||
|   - cronjob.yaml | ||||
							
								
								
									
										21
									
								
								infrastructure/backup/postgres/postgres.sealedsecret.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								infrastructure/backup/postgres/postgres.sealedsecret.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| { | ||||
|   "kind": "SealedSecret", | ||||
|   "apiVersion": "bitnami.com/v1alpha1", | ||||
|   "metadata": { | ||||
|     "name": "postgres-password", | ||||
|     "namespace": "backup", | ||||
|     "creationTimestamp": null | ||||
|   }, | ||||
|   "spec": { | ||||
|     "template": { | ||||
|       "metadata": { | ||||
|         "name": "postgres-password", | ||||
|         "namespace": "backup", | ||||
|         "creationTimestamp": null | ||||
|       } | ||||
|     }, | ||||
|     "encryptedData": { | ||||
|       "password": "AgBKXybtQWxHVX0UeQ9z5VOSJp9dadp+j+8VxBzyh37BdfLA9l5YppOWgK2RpmQmFmcrrxr7u2SgyJ4rP60n0r8LHLcmPTXAUJe5b07HTVOLn8Q4C9ObEkWVXBycmI5Kc8vHZ+OW8T3s/QqrnLIlQPOq56mjsWjO24O/72aUl4IzlrSq3NYPAMpQOwfgoam/4ZaHed6+Im40eQalkEWRlk5KOkSayWsrNJNccAhnZ8JapCP25pVVfz5xJc9286jNqTCgGt1Ez3xTXbd3LPI2QgeonIPU9zqlXeQgjS/UuAIuKyEW7ypD2/7lLoU1Yk4XMzIreVSrYgfy7ylnC++FPZBI+32/ocbEgpXPX9O/gb2tQLANVEn9BwVyPe3MW/vB63ryyfhtrPQbNJCJNnwKlsoS+HcVYBGAAtjdUYD4/2fKabH7Th2SlMIJvGBwhxpJo1bnblHoTUQ/Ao5gaUIcZC0qCnd9ZKVRKwtFsJrgqnEAapd9dNdDu9RBxVKAUa0TS+ahnXBaC87lvydb/9PxLz+J7E27oInt9coFEHpaZFNdt0QJXUqs3DF0JO7ll3wC+R1iDUWRY3NKf/bpiGgkwk3VtUkIXcW5biaD7lF8inrLVzktvQGET/CbYre5ws9qj5xF4NUYUivYexiP8isScnbrys671GizUjxFoPQpWotEHmZ9DNsIYOF3OvewKjDllpo1izKmY1Y=" | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										13
									
								
								infrastructure/backup/postgres/pvc.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								infrastructure/backup/postgres/pvc.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| kind: PersistentVolumeClaim | ||||
| apiVersion: v1 | ||||
|  | ||||
| metadata: | ||||
|   name: postgres-backup-claim | ||||
|  | ||||
| spec: | ||||
|   storageClassName: nfs-client | ||||
|   accessModes: | ||||
|     - ReadWriteOnce | ||||
|   resources: | ||||
|     requests: | ||||
|       storage: 10Gi | ||||
		Reference in New Issue
	
	Block a user