Skip to content

Commit 4555df3

Browse files
committed
Add "compression" flag to use native CloudSQL export file compression
1 parent b8c5356 commit 4555df3

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/trufflesecurity/cloudsql-exporter
1+
module github.com/flashadmin/cloudsql-exporter
22

33
go 1.19
44

main.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"google.golang.org/api/storage/v1"
1313
"gopkg.in/alecthomas/kingpin.v2"
1414

15-
"github.com/trufflesecurity/cloudsql-exporter/pkg/cloudsql"
16-
"github.com/trufflesecurity/cloudsql-exporter/pkg/version"
15+
"github.com/flashadmin/cloudsql-exporter/pkg/cloudsql"
16+
"github.com/flashadmin/cloudsql-exporter/pkg/version"
1717
)
1818

1919
var (
@@ -22,6 +22,7 @@ var (
2222
bucket = app.Flag("bucket", "Google Cloud Storage bucket name").Required().String()
2323
project = app.Flag("project", "GCP project ID").Required().String()
2424
instance = app.Flag("instance", "Cloud SQL instance name, if not specified all within the project will be enumerated").String()
25+
compression = app.Flag("compression", "Enable compression for exported SQL files").Bool()
2526
ensureIamBindings = app.Flag("ensure-iam-bindings", "Ensure that the Cloud SQL service account has the required IAM role binding to export and validate the backup").Bool()
2627
)
2728

@@ -70,7 +71,15 @@ func main() {
7071
}
7172
}
7273

73-
err := cloudsql.ExportCloudSQLDatabase(ctx, sqlAdminSvc, databases, *project, string(instance), *bucket, time.Now().Format(time.RFC3339Nano))
74+
var objectName string
75+
76+
if *compression {
77+
objectName = time.Now().Format(time.RFC3339Nano) + ".sql.gz"
78+
} else {
79+
objectName = time.Now().Format(time.RFC3339Nano) + ".sql"
80+
}
81+
82+
err := cloudsql.ExportCloudSQLDatabase(ctx, sqlAdminSvc, databases, *project, string(instance), *bucket, objectName)
7483
if err != nil {
7584
log.Fatal(err)
7685
}

pkg/cloudsql/cloudsql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func ExportCloudSQLDatabase(ctx context.Context, sqlAdminSvc *sqladmin.Service,
126126
FileType: "SQL",
127127
Kind: "sql#exportContext",
128128
Databases: []string{database},
129-
Uri: fmt.Sprintf("gs://%s/%s/%s/%s/%s.sql", bucketName, projectID, instanceID, database, objectName),
129+
Uri: fmt.Sprintf("gs://%s/%s/%s/%s/%s", bucketName, projectID, instanceID, database, objectName),
130130
},
131131
}
132132

0 commit comments

Comments
 (0)