Prepare more than 1 step backup

This commit is contained in:
jandre 2020-12-28 15:42:15 +01:00
parent 13c1b4220a
commit 16502993dd
5 changed files with 123 additions and 113 deletions

View File

@ -31,7 +31,7 @@ RUN cp /build/formolcli .
FROM arm32v7/alpine:3.12
RUN apk add --no-cache restic
COPY bin/restic /usr/local/bin
#COPY bin/restic /usr/local/bin
COPY --from=builder /dist/formolcli /usr/local/bin
# Command to run

View File

@ -1,6 +1,10 @@
IMG ?= desmo999r/formolcli:latest
docker-build:
podman build --disable-compression --format=docker . -t ${IMG}
IMG-deployment ?= desmo999r/formolcli:latest
docker-build-deployment:
podman build --disable-compression --format=docker --file Dockerfile.deployment -t ${IMG-deployment}
docker-push:
podman push ${IMG}
docker-push-deployment:
podman push ${IMG-deployment}
deployment: docker-build-deployment docker-push-deployment
all: deployment

View File

@ -3,7 +3,7 @@ module github.com/desmo999r/formolcli
go 1.14
require (
github.com/desmo999r/formol v0.6.2-0.20201212121852-aa511e03435a
github.com/desmo999r/formol v0.6.2-0.20201228110830-3aaf127e5835
github.com/go-logr/logr v0.1.0
github.com/go-logr/zapr v0.1.0
github.com/mitchellh/go-homedir v1.1.0

View File

@ -15,7 +15,7 @@ var (
passwordFile string
aws_access_key_id string
aws_secret_access_key string
resticExec = "/usr/local/bin/restic"
resticExec = "/usr/bin/restic"
logger logr.Logger
)

View File

@ -131,18 +131,15 @@ func (r *BackupSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
return ctrl.Result{}, client.IgnoreNotFound(err)
}
// Found the BackupConfiguration.
log.V(1).Info("Found BackupConfiguration", "BackupConfiguration", backupConf.Name)
// Found the BackupConfiguration.
if backupConf.Spec.Target.Name != deploymentName {
log.V(0).Info("Not for us", "target", backupConf.Spec.Target.Name, "us", deploymentName)
return ctrl.Result{}, nil
}
backupDeployment := func(target formolv1alpha1.Target) error {
log.V(0).Info("before", "backupsession", backupSession)
backupSession.Status.BackupSessionState = formolv1alpha1.Running
if err := r.Client.Status().Update(ctx, backupSession); err != nil {
log.Error(err, "unable to update status", "backupsession", backupSession)
return ctrl.Result{}, err
return err
}
// Preparing for backup
c := make(chan []byte)
@ -170,24 +167,21 @@ func (r *BackupSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
}
}()
// do the backup
switch backupConf.Spec.Target.Kind {
case "Deployment":
backupSession.Status.StartTime = &metav1.Time {Time: time.Now()}
if err := backup.BackupDeployment("", backupConf.Spec.Paths, c); err != nil {
if err := backup.BackupDeployment("", target.Paths, c); err != nil {
log.Error(err, "unable to backup deployment")
return ctrl.Result{}, err
return err
}
result = formolv1alpha1.Success
}
// cleanup old backups
backupSessionList := &formolv1alpha1.BackupSessionList{}
if err := r.List(ctx, backupSessionList, client.InNamespace(backupConf.Namespace), client.MatchingFieldsSelector{fields.SelectorFromSet(fields.Set{sessionState: "Success"})}); err != nil {
return ctrl.Result{}, nil
return nil
}
if len(backupSessionList.Items) < 2 {
// Not enough backupSession to proceed
return ctrl.Result{}, nil
return nil
}
sort.Slice(backupSessionList.Items, func(i, j int) bool {
@ -255,6 +249,18 @@ func (r *BackupSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
}
}
}
return nil
}
for _, target := range backupConf.Spec.Targets {
switch target.Kind {
case "Deployment":
if target.Name == deploymentName {
log.V(0).Info("It's for us!", "target", target)
return ctrl.Result{}, backupDeployment(target)
}
}
}
return ctrl.Result{}, nil
}