-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpostgres.go
42 lines (34 loc) · 1.31 KB
/
postgres.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package lib
import (
"log"
"path/filepath"
)
func EnsurePostgresAvailable(namespace string, config PostgresConfig) error {
log.Printf("Checking if Postgres is available in namespace '%s'...", namespace)
return KubectlExecTemplate(namespace, config.ExecResource, config.ExecContainer, GetTemplateAtlas().PostgresCheck, config)
}
func DumpPostgres(namespace string, dryRun bool, config PostgresConfig) error {
if dryRun {
log.Println("Skipping Postgres backup - dry run mode is active")
return nil
}
log.Printf("Backing up Postgres database '%s' in namespace '%s'...", config.DB, namespace)
// Create template data with computed fields
type templateData struct {
PostgresConfig
DumpFileDir string
}
data := templateData{
PostgresConfig: config,
DumpFileDir: filepath.Dir(config.DumpFile),
}
return KubectlExecTemplate(namespace, config.ExecResource, config.ExecContainer, GetTemplateAtlas().PostgresDump, data)
}
func RestorePostgres(namespace string, dryRun bool, config PostgresConfig) error {
if dryRun {
log.Println("Skipping Postgres restore - dry run mode is active")
return nil
}
log.Printf("Restoring Postgres database '%s' in namespace '%s'...", config.DB, namespace)
return KubectlExecTemplate(namespace, config.ExecResource, config.ExecContainer, GetTemplateAtlas().PostgresRestore, config)
}