Skip to content

Commit fbd0489

Browse files
author
Pavel Tumik
authored
Add ability to upload logical backup to gcs (#1173)
Support logical backup provider/storage S3 and GCS equivalent
1 parent 9290758 commit fbd0489

File tree

7 files changed

+58
-17
lines changed

7 files changed

+58
-17
lines changed

docker/logical-backup/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ RUN apt-get update \
1313
curl \
1414
jq \
1515
gnupg \
16+
gcc \
17+
libffi-dev \
1618
&& pip3 install --no-cache-dir awscli --upgrade \
19+
&& pip3 install --no-cache-dir gsutil --upgrade \
1720
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
1821
&& cat /etc/apt/sources.list.d/pgdg.list \
1922
&& curl --silent https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \

docker/logical-backup/dump.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ function aws_upload {
4646
aws s3 cp - "$PATH_TO_BACKUP" "${args[@]//\'/}"
4747
}
4848

49+
function gcs_upload {
50+
PATH_TO_BACKUP=gs://$LOGICAL_BACKUP_S3_BUCKET"/spilo/"$SCOPE$LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX"/logical_backups/"$(date +%s).sql.gz
51+
52+
gsutil -o Credentials:gs_service_key_file=$LOGICAL_BACKUP_GOOGLE_APPLICATION_CREDENTIALS cp - "$PATH_TO_BACKUP"
53+
}
54+
55+
function upload {
56+
case $LOGICAL_BACKUP_PROVIDER in
57+
"gcs")
58+
gcs_upload
59+
;;
60+
*)
61+
aws_upload $(($(estimate_size) / DUMP_SIZE_COEFF))
62+
;;
63+
esac
64+
}
65+
4966
function get_pods {
5067
declare -r SELECTOR="$1"
5168

@@ -93,7 +110,7 @@ for search in "${search_strategy[@]}"; do
93110
done
94111

95112
set -x
96-
dump | compress | aws_upload $(($(estimate_size) / DUMP_SIZE_COEFF))
113+
dump | compress | upload
97114
[[ ${PIPESTATUS[0]} != 0 || ${PIPESTATUS[1]} != 0 || ${PIPESTATUS[2]} != 0 ]] && (( ERRORCOUNT += 1 ))
98115
set +x
99116

docs/reference/operator_parameters.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,10 @@ grouped under the `logical_backup` key.
563563
The default image is the same image built with the Zalando-internal CI
564564
pipeline. Default: "registry.opensource.zalan.do/acid/logical-backup"
565565

566+
* **logical_backup_provider**
567+
Specifies the storage provider to which the backup should be uploaded (`s3` or `gcs`).
568+
Default: "s3"
569+
566570
* **logical_backup_s3_bucket**
567571
S3 bucket to store backup results. The bucket has to be present and
568572
accessible by Postgres pods. Default: empty.
@@ -583,6 +587,9 @@ grouped under the `logical_backup` key.
583587
* **logical_backup_s3_secret_access_key**
584588
When set, value will be in AWS_SECRET_ACCESS_KEY env variable. The Default is empty.
585589

590+
* **logical_backup_google_application_credentials**
591+
Specifies the path of the google cloud service account json file. Default is empty.
592+
586593
## Debugging the operator
587594

588595
Options to aid debugging of the operator itself. Grouped under the `debug` key.

pkg/apis/acid.zalan.do/v1/operator_configuration_type.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,16 @@ type ConnectionPoolerConfiguration struct {
186186

187187
// OperatorLogicalBackupConfiguration defines configuration for logical backup
188188
type OperatorLogicalBackupConfiguration struct {
189-
Schedule string `json:"logical_backup_schedule,omitempty"`
190-
DockerImage string `json:"logical_backup_docker_image,omitempty"`
191-
S3Bucket string `json:"logical_backup_s3_bucket,omitempty"`
192-
S3Region string `json:"logical_backup_s3_region,omitempty"`
193-
S3Endpoint string `json:"logical_backup_s3_endpoint,omitempty"`
194-
S3AccessKeyID string `json:"logical_backup_s3_access_key_id,omitempty"`
195-
S3SecretAccessKey string `json:"logical_backup_s3_secret_access_key,omitempty"`
196-
S3SSE string `json:"logical_backup_s3_sse,omitempty"`
189+
Schedule string `json:"logical_backup_schedule,omitempty"`
190+
DockerImage string `json:"logical_backup_docker_image,omitempty"`
191+
BackupProvider string `json:"logical_backup_provider,omitempty"`
192+
S3Bucket string `json:"logical_backup_s3_bucket,omitempty"`
193+
S3Region string `json:"logical_backup_s3_region,omitempty"`
194+
S3Endpoint string `json:"logical_backup_s3_endpoint,omitempty"`
195+
S3AccessKeyID string `json:"logical_backup_s3_access_key_id,omitempty"`
196+
S3SecretAccessKey string `json:"logical_backup_s3_secret_access_key,omitempty"`
197+
S3SSE string `json:"logical_backup_s3_sse,omitempty"`
198+
GoogleApplicationCredentials string `json:"logical_backup_google_application_credentials,omitempty"`
197199
}
198200

199201
// OperatorConfigurationData defines the operation config

pkg/cluster/k8sres.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,10 @@ func (c *Cluster) generateLogicalBackupPodEnvVars() []v1.EnvVar {
19881988
},
19891989
},
19901990
// Bucket env vars
1991+
{
1992+
Name: "LOGICAL_BACKUP_PROVIDER",
1993+
Value: c.OpConfig.LogicalBackup.LogicalBackupProvider,
1994+
},
19911995
{
19921996
Name: "LOGICAL_BACKUP_S3_BUCKET",
19931997
Value: c.OpConfig.LogicalBackup.LogicalBackupS3Bucket,
@@ -2008,6 +2012,10 @@ func (c *Cluster) generateLogicalBackupPodEnvVars() []v1.EnvVar {
20082012
Name: "LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX",
20092013
Value: getBucketScopeSuffix(string(c.Postgresql.GetUID())),
20102014
},
2015+
{
2016+
Name: "LOGICAL_BACKUP_GOOGLE_APPLICATION_CREDENTIALS",
2017+
Value: c.OpConfig.LogicalBackup.LogicalBackupGoogleApplicationCredentials,
2018+
},
20112019
// Postgres env vars
20122020
{
20132021
Name: "PG_VERSION",

pkg/controller/operator_config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,14 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur
146146
// logical backup config
147147
result.LogicalBackupSchedule = util.Coalesce(fromCRD.LogicalBackup.Schedule, "30 00 * * *")
148148
result.LogicalBackupDockerImage = util.Coalesce(fromCRD.LogicalBackup.DockerImage, "registry.opensource.zalan.do/acid/logical-backup")
149+
result.LogicalBackupProvider = util.Coalesce(fromCRD.LogicalBackup.BackupProvider, "s3")
149150
result.LogicalBackupS3Bucket = fromCRD.LogicalBackup.S3Bucket
150151
result.LogicalBackupS3Region = fromCRD.LogicalBackup.S3Region
151152
result.LogicalBackupS3Endpoint = fromCRD.LogicalBackup.S3Endpoint
152153
result.LogicalBackupS3AccessKeyID = fromCRD.LogicalBackup.S3AccessKeyID
153154
result.LogicalBackupS3SecretAccessKey = fromCRD.LogicalBackup.S3SecretAccessKey
154155
result.LogicalBackupS3SSE = fromCRD.LogicalBackup.S3SSE
156+
result.LogicalBackupGoogleApplicationCredentials = fromCRD.LogicalBackup.GoogleApplicationCredentials
155157

156158
// debug config
157159
result.DebugLogging = fromCRD.OperatorDebug.DebugLogging

pkg/util/config/config.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,16 @@ type Scalyr struct {
111111

112112
// LogicalBackup defines configuration for logical backup
113113
type LogicalBackup struct {
114-
LogicalBackupSchedule string `name:"logical_backup_schedule" default:"30 00 * * *"`
115-
LogicalBackupDockerImage string `name:"logical_backup_docker_image" default:"registry.opensource.zalan.do/acid/logical-backup"`
116-
LogicalBackupS3Bucket string `name:"logical_backup_s3_bucket" default:""`
117-
LogicalBackupS3Region string `name:"logical_backup_s3_region" default:""`
118-
LogicalBackupS3Endpoint string `name:"logical_backup_s3_endpoint" default:""`
119-
LogicalBackupS3AccessKeyID string `name:"logical_backup_s3_access_key_id" default:""`
120-
LogicalBackupS3SecretAccessKey string `name:"logical_backup_s3_secret_access_key" default:""`
121-
LogicalBackupS3SSE string `name:"logical_backup_s3_sse" default:""`
114+
LogicalBackupSchedule string `name:"logical_backup_schedule" default:"30 00 * * *"`
115+
LogicalBackupDockerImage string `name:"logical_backup_docker_image" default:"registry.opensource.zalan.do/acid/logical-backup"`
116+
LogicalBackupProvider string `name:"logical_backup_provider" default:"s3"`
117+
LogicalBackupS3Bucket string `name:"logical_backup_s3_bucket" default:""`
118+
LogicalBackupS3Region string `name:"logical_backup_s3_region" default:""`
119+
LogicalBackupS3Endpoint string `name:"logical_backup_s3_endpoint" default:""`
120+
LogicalBackupS3AccessKeyID string `name:"logical_backup_s3_access_key_id" default:""`
121+
LogicalBackupS3SecretAccessKey string `name:"logical_backup_s3_secret_access_key" default:""`
122+
LogicalBackupS3SSE string `name:"logical_backup_s3_sse" default:""`
123+
LogicalBackupGoogleApplicationCredentials string `name:"logical_backup_google_application_credentials" default:""`
122124
}
123125

124126
// Operator options for connection pooler

0 commit comments

Comments
 (0)