48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
|
package actions
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"flow/services/internal/config"
|
||
|
"flow/services/internal/services"
|
||
|
)
|
||
|
|
||
|
const containerRunModeBackup = "backup"
|
||
|
|
||
|
func Backup(environment, service string) error {
|
||
|
cfg, err := config.NewConfig(environment)
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("unable to load the configuration; %w", err)
|
||
|
}
|
||
|
|
||
|
switch service {
|
||
|
case services.Forgejo:
|
||
|
cfg.Forgejo.ContainerRunMode = containerRunModeBackup
|
||
|
default:
|
||
|
fmt.Printf("Backup is not supported for %q.\n", service)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
if err := backup(cfg, environment, service); err != nil {
|
||
|
return fmt.Errorf("error performing a backup of %q; %w", service, err)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func backup(cfg config.Config, environment, service string) error {
|
||
|
if err := stop(cfg.Docker.Host, environment, service); err != nil {
|
||
|
return fmt.Errorf("unable to stop %q; %w", service, err)
|
||
|
}
|
||
|
|
||
|
if err := prepareCompose(cfg, environment); err != nil {
|
||
|
return fmt.Errorf("unable to regenerate the compose file for the backup; %w", err)
|
||
|
}
|
||
|
|
||
|
if err := deploy(cfg.Docker.Host, environment, service, false); err != nil {
|
||
|
return fmt.Errorf("error deploying the backup container; %w", err)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|