Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
postgresql-rclone
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
137d11db
authored
2023-01-26 15:01:57 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Implement restore, rename chart to be postgresql-rclone.
1 parent
6edf09b2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
143 additions
and
37 deletions
Chart.yaml
templates/_helpers.tpl
templates/cronjob.yaml
values.yaml
Chart.yaml
View file @
137d11d
apiVersion
:
v2
name
:
postgresql-
backup-s3
name
:
postgresql-
rclone
description
:
A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
...
...
templates/_helpers.tpl
View file @
137d11d
{{
/*
Expand
the
name
of
the
chart
.
*/
}}
{{- define "postgresql-
backup-s3
.name" -}}
{{- define "postgresql-
rclone
.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
...
...
@@ -10,7 +10,7 @@ Create a default fully qualified app name.
We
truncate
at
63
chars
because
some
Kubernetes
name
fields
are
limited
to
this
(
by
the
DNS
naming
spec
).
If
release
name
contains
chart
name
it
will
be
used
as
a
full
name
.
*/
}
}
{{- define "postgresql-
backup-s3
.fullname" -}}
{{- define "postgresql-
rclone
.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
...
...
@@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name.
{
{
/*
Create
chart
name
and
version
as
used
by
the
chart
label
.
*/
}
}
{{- define "postgresql-
backup-s3
.chart" -}}
{{- define "postgresql-
rclone
.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{
{
/*
Common
labels
*/
}
}
{{- define "postgresql-
backup-s3
.labels" -}}
helm.sh/chart: {{ include "postgresql-
backup-s3
.chart" . }}
{{ include "postgresql-
backup-s3
.selectorLabels" . }}
{{- define "postgresql-
rclone
.labels" -}}
helm.sh/chart: {{ include "postgresql-
rclone
.chart" . }}
{{ include "postgresql-
rclone
.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
...
...
@@ -45,15 +45,15 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{
{
/*
Selector
labels
*/
}
}
{{- define "postgresql-
backup-s3
.selectorLabels" -}}
app.kubernetes.io/name: {{ include "postgresql-
backup-s3
.name" . }}
{{- define "postgresql-
rclone
.selectorLabels" -}}
app.kubernetes.io/name: {{ include "postgresql-
rclone
.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{
{
/*
Create
the
name
of
the
service
account
to
use
*/
}
}
{{- define "postgresql-
backup-s3
.serviceAccountName" -}}
{{- define "postgresql-
rclone
.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "postgresql-backup-restore.fullname" .) .Values.serviceAccount.name }}
{{- else }}
...
...
templates/cronjob.yaml
View file @
137d11d
...
...
@@ -2,7 +2,7 @@
apiVersion
:
v1
kind
:
PersistentVolumeClaim
metadata
:
name
:
{{
include "postgresql-
backup-s3.fullname" .
}}
name
:
{{
include "postgresql-
rclone.fullname" .
}}
-backups
spec
:
storageClassName
:
{{
.Values.backup.pvc.storageClassName
}}
accessModes
:
...
...
@@ -14,7 +14,7 @@ spec:
apiVersion
:
v1
kind
:
ConfigMap
metadata
:
name
:
{{
include "postgresql-
backup-s3.fullname" .
}}
-local
name
:
{{
include "postgresql-
rclone.fullname" .
}}
-backup
-local
data
:
POSTGRES_DB
:
|-
{{- range $database := .Values.postgresql.databases }}
...
...
@@ -25,7 +25,7 @@ data:
apiVersion
:
v1
kind
:
Secret
metadata
:
name
:
{{
include "postgresql-
backup-s3
.fullname" .
}}
-auth
name
:
{{
include "postgresql-
rclone
.fullname" .
}}
-auth
stringData
:
POSTGRES_USER
:
{{
.Values.postgresql.auth.postgresqlUser
}}
POSTGRES_PASSWORD
:
{{
.Values.postgresql.auth.postgresqlPassword
}}
...
...
@@ -34,7 +34,7 @@ stringData:
apiVersion
:
v1
kind
:
ConfigMap
metadata
:
name
:
{{
include "postgresql-
backup-s3
.fullname" .
}}
-rclone
name
:
{{
include "postgresql-
rclone
.fullname" .
}}
-rclone
data
:
{{
.Values.rclone.config | toYaml | nindent 2
}}
{{
- end
}}
...
...
@@ -43,17 +43,17 @@ data:
apiVersion
:
v1
kind
:
Secret
metadata
:
name
:
{{
include "postgresql-
backup-s3
.fullname" .
}}
-rclone
name
:
{{
include "postgresql-
rclone
.fullname" .
}}
-rclone
stringData
:
{{
.Values.rclone.secret | toYaml | nindent 2
}}
{{
- end
}}
---
apiVersion
:
batch/v1
beta1
apiVersion
:
batch/v1
kind
:
CronJob
metadata
:
name
:
{{
include "postgresql-
backup-s3.fullname" .
}}
name
:
{{
include "postgresql-
rclone.fullname" .
}}
-backup
labels
:
{{
- include "postgresql-
backup-s3
.labels" . | nindent 4
}}
{{
- include "postgresql-
rclone
.labels" . | nindent 4
}}
spec
:
schedule
:
{{
.Values.backup.schedule
}}
startingDeadlineSeconds
:
3600
...
...
@@ -68,29 +68,29 @@ spec:
imagePullSecrets
:
{{
- toYaml .Values.imagePullSecrets | nindent 12
}}
volumes
:
-
name
:
dbdum
ps
-
name
:
backu
ps
persistentVolumeClaim
:
claimName
:
{{
include "postgresql-
backup-s3.fullname" .
}}
claimName
:
{{
include "postgresql-
rclone.fullname" .
}}
-backups
-
name
:
postgresql-auth
secret
:
secretName
:
{{
include "postgresql-
backup-s3
.fullname" .
}}
-auth
secretName
:
{{
include "postgresql-
rclone
.fullname" .
}}
-auth
-
name
:
local-config
configMap
:
name
:
{{
include "postgresql-
backup-s3
.fullname" .
}}
-local
name
:
{{
include "postgresql-
rclone
.fullname" .
}}
-local
{{
- if .Values.rclone.enabled
}}
-
name
:
rclone-auth
secret
:
secretName
:
{{
include "postgresql-
backup-s3
.fullname" .
}}
-rclone
secretName
:
{{
include "postgresql-
rclone
.fullname" .
}}
-rclone
-
name
:
rclone-config
configMap
:
name
:
{{
include "postgresql-
backup-s3
.fullname" .
}}
-rclone
name
:
{{
include "postgresql-
rclone
.fullname" .
}}
-rclone
{{
- end
}}
initContainers
:
-
name
:
dump-databases
image
:
"
{{
.Values.local.image.repository
}}:{{
.Values.local.image.tag
}}"
imagePullPolicy
:
{{
.Values.local.image.pullPolicy
}}
volumeMounts
:
-
name
:
dbdum
ps
-
name
:
backu
ps
mountPath
:
/backups
-
name
:
local-config
mountPath
:
/config
...
...
@@ -100,7 +100,7 @@ spec:
-
name
:
BACKUP_KEEP_DAYS
valueFrom
:
configMapKeyRef
:
name
:
{{
include "postgresql-
backup-s3
.fullname" .
}}
-local
name
:
{{
include "postgresql-
rclone
.fullname" .
}}
-local
key
:
BACKUP_KEEP_DAYS
-
name
:
BACKUP_DIR
value
:
/backups
...
...
@@ -118,7 +118,7 @@ spec:
image
:
"
{{
.Values.rclone.image.repository
}}:{{
.Values.rclone.image.tag
}}"
imagePullPolicy
:
{{
.Values.rclone.image.pullPolicy
}}
volumeMounts
:
-
name
:
dbdum
ps
-
name
:
backu
ps
mountPath
:
/backups
-
name
:
rclone-config
mountPath
:
/config
...
...
@@ -126,9 +126,9 @@ spec:
mountPath
:
/secret
envFrom
:
-
configMapRef
:
name
:
{{
include "postgresql-
backup-s3
.fullname" .
}}
-rclone
name
:
{{
include "postgresql-
rclone
.fullname" .
}}
-rclone
-
secretRef
:
name
:
{{
include "postgresql-
backup-s3
.fullname" .
}}
-rclone
name
:
{{
include "postgresql-
rclone
.fullname" .
}}
-rclone
{{
- if .Values.rclone.crypt.enabled
}}
env
:
-
name
:
RCLONE_CRYPT_REMOTE
...
...
@@ -144,8 +144,111 @@ spec:
-
name
:
show-dumps
image
:
bash
volumeMounts
:
-
name
:
dbdum
ps
-
name
:
backu
ps
mountPath
:
/backups
command
:
[
"
ls"
]
args
:
[
"
-alR"
,
"
/backups"
]
---
apiVersion
:
v1
kind
:
PersistentVolumeClaim
metadata
:
name
:
{{
include "postgresql-rclone.fullname" .
}}
-restores
spec
:
storageClassName
:
{{
.Values.restore.pvc.storageClassName
}}
accessModes
:
-
ReadWriteOnce
resources
:
requests
:
storage
:
{{
.Values.restore.pvc.size
}}
---
apiVersion
:
batch/v1
kind
:
Job
metadata
:
name
:
{{
include "postgresql-rclone.fullname" .
}}
-restore
labels
:
{{
- include "postgresql-rclone.labels" . | nindent 4
}}
spec
:
template
:
spec
:
restartPolicy
:
OnFailure
imagePullSecrets
:
{{
- toYaml .Values.imagePullSecrets | nindent 12
}}
volumes
:
-
name
:
restores
persistentVolumeClaim
:
claimName
:
{{
include "postgresql-rclone.fullname" .
}}
-restores
{{
- if .Values.rclone.enabled
}}
-
name
:
rclone-auth
secret
:
secretName
:
{{
include "postgresql-rclone.fullname" .
}}
-rclone
-
name
:
rclone-config
configMap
:
name
:
{{
include "postgresql-rclone.fullname" .
}}
-rclone
{{
- end
}}
initContainers
:
{{
- if .Values.rclone.enabled
}}
-
name
:
rclone
image
:
"
{{
.Values.rclone.image.repository
}}:{{
.Values.rclone.image.tag
}}"
imagePullPolicy
:
{{
.Values.rclone.image.pullPolicy
}}
volumeMounts
:
-
name
:
restores
mountPath
:
/restores
-
name
:
rclone-config
mountPath
:
/config
-
name
:
rclone-auth
mountPath
:
/secret
envFrom
:
-
configMapRef
:
name
:
{{
include "postgresql-rclone.fullname" .
}}
-rclone
-
secretRef
:
name
:
{{
include "postgresql-rclone.fullname" .
}}
-rclone
{{
- if .Values.rclone.crypt.enabled
}}
env
:
-
name
:
RCLONE_CRYPT_REMOTE
value
:
"
:s3:$(S3_BUCKET)/$(S3_PREFIX)/last/"
{{
- end
}}
{{
- if .Values.rclone.crypt.enabled
}}
args
:
[
"
copy"
,
"
:crypt:"
,
"
/restores/"
]
{{
- else
}}
args
:
[
"
-v"
,
"
copy"
,
"
:s3:$(S3_BUCKET)/$(S3_PREFIX)/last/"
,
"
/restores/.work/"
]
{{
- end
}}
{{
- end
}}
-
name
:
link-latest
image
:
"
{{
.Values.bash.image.repository
}}:{{
.Values.bash.image.tag
}}"
imagePullPolicy
:
{{
.Values.bash.image.pullPolicy
}}
volumeMounts
:
-
name
:
restores
mountPath
:
/restores
command
:
-
bash
-
-cx
-
|-
find /restores/.work -maxdepth 1 -mindepth 1 -name '*.sql.gz' | \
sort | \
awk '{split($1, a, /-([^-]*)-([^-]*)$/)} !uniq[a[1] a[2] a[3]]++' | \
while read file; do \
ln -f "$file" "/restores/"
done
-
name
:
show-restores
image
:
"
{{
.Values.bash.image.repository
}}:{{
.Values.bash.image.tag
}}"
imagePullPolicy
:
{{
.Values.bash.image.pullPolicy
}}
volumeMounts
:
-
name
:
restores
mountPath
:
/restores
command
:
[
"
ls"
]
args
:
[
"
-alR"
,
"
/restores"
]
containers
:
-
name
:
ready
image
:
"
{{
.Values.bash.image.repository
}}:{{
.Values.bash.image.tag
}}"
imagePullPolicy
:
{{
.Values.bash.image.pullPolicy
}}
volumeMounts
:
-
name
:
restores
mountPath
:
/restores
command
:
-
bash
-
-cx
-
|-
touch /restores/.restored
...
...
values.yaml
View file @
137d11d
...
...
@@ -2,13 +2,11 @@
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
s3
:
bucket
:
"
"
prefix
:
"
"
region
:
"
us-east-1"
provider
:
"
aws"
accessKey
:
"
"
secretKey
:
"
"
bash
:
image
:
repository
:
bash
tag
:
latest
pullPolicy
:
IfNotPresent
postgresql
:
host
:
postgresql.postgresql.svc.cluster.local
...
...
@@ -33,6 +31,11 @@ backup:
storageClassName
:
"
"
size
:
10Gi
restore
:
pvc
:
storageClassName
:
"
"
size
:
10Gi
rclone
:
enabled
:
false
image
:
...
...
Please
register
or
sign in
to post a comment