Prepare more than 1 step backup
This commit is contained in:
parent
13c1b4220a
commit
16502993dd
@ -31,7 +31,7 @@ RUN cp /build/formolcli .
|
|||||||
FROM arm32v7/alpine:3.12
|
FROM arm32v7/alpine:3.12
|
||||||
|
|
||||||
RUN apk add --no-cache restic
|
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
|
COPY --from=builder /dist/formolcli /usr/local/bin
|
||||||
|
|
||||||
# Command to run
|
# Command to run
|
||||||
14
Makefile
14
Makefile
@ -1,6 +1,10 @@
|
|||||||
IMG ?= desmo999r/formolcli:latest
|
IMG-deployment ?= desmo999r/formolcli:latest
|
||||||
docker-build:
|
docker-build-deployment:
|
||||||
podman build --disable-compression --format=docker . -t ${IMG}
|
podman build --disable-compression --format=docker --file Dockerfile.deployment -t ${IMG-deployment}
|
||||||
|
|
||||||
docker-push:
|
docker-push-deployment:
|
||||||
podman push ${IMG}
|
podman push ${IMG-deployment}
|
||||||
|
|
||||||
|
deployment: docker-build-deployment docker-push-deployment
|
||||||
|
|
||||||
|
all: deployment
|
||||||
|
|||||||
@ -3,7 +3,7 @@ module github.com/desmo999r/formolcli
|
|||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require (
|
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/logr v0.1.0
|
||||||
github.com/go-logr/zapr v0.1.0
|
github.com/go-logr/zapr v0.1.0
|
||||||
github.com/mitchellh/go-homedir v1.1.0
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
|
|||||||
@ -15,7 +15,7 @@ var (
|
|||||||
passwordFile string
|
passwordFile string
|
||||||
aws_access_key_id string
|
aws_access_key_id string
|
||||||
aws_secret_access_key string
|
aws_secret_access_key string
|
||||||
resticExec = "/usr/local/bin/restic"
|
resticExec = "/usr/bin/restic"
|
||||||
logger logr.Logger
|
logger logr.Logger
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -131,18 +131,15 @@ func (r *BackupSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
|||||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Found the BackupConfiguration.
|
||||||
log.V(1).Info("Found BackupConfiguration", "BackupConfiguration", backupConf.Name)
|
log.V(1).Info("Found BackupConfiguration", "BackupConfiguration", backupConf.Name)
|
||||||
|
|
||||||
// Found the BackupConfiguration.
|
backupDeployment := func(target formolv1alpha1.Target) error {
|
||||||
if backupConf.Spec.Target.Name != deploymentName {
|
|
||||||
log.V(0).Info("Not for us", "target", backupConf.Spec.Target.Name, "us", deploymentName)
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
|
||||||
log.V(0).Info("before", "backupsession", backupSession)
|
log.V(0).Info("before", "backupsession", backupSession)
|
||||||
backupSession.Status.BackupSessionState = formolv1alpha1.Running
|
backupSession.Status.BackupSessionState = formolv1alpha1.Running
|
||||||
if err := r.Client.Status().Update(ctx, backupSession); err != nil {
|
if err := r.Client.Status().Update(ctx, backupSession); err != nil {
|
||||||
log.Error(err, "unable to update status", "backupsession", backupSession)
|
log.Error(err, "unable to update status", "backupsession", backupSession)
|
||||||
return ctrl.Result{}, err
|
return err
|
||||||
}
|
}
|
||||||
// Preparing for backup
|
// Preparing for backup
|
||||||
c := make(chan []byte)
|
c := make(chan []byte)
|
||||||
@ -170,24 +167,21 @@ func (r *BackupSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
// do the backup
|
// do the backup
|
||||||
switch backupConf.Spec.Target.Kind {
|
|
||||||
case "Deployment":
|
|
||||||
backupSession.Status.StartTime = &metav1.Time {Time: time.Now()}
|
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")
|
log.Error(err, "unable to backup deployment")
|
||||||
return ctrl.Result{}, err
|
return err
|
||||||
}
|
}
|
||||||
result = formolv1alpha1.Success
|
result = formolv1alpha1.Success
|
||||||
}
|
|
||||||
|
|
||||||
// cleanup old backups
|
// cleanup old backups
|
||||||
backupSessionList := &formolv1alpha1.BackupSessionList{}
|
backupSessionList := &formolv1alpha1.BackupSessionList{}
|
||||||
if err := r.List(ctx, backupSessionList, client.InNamespace(backupConf.Namespace), client.MatchingFieldsSelector{fields.SelectorFromSet(fields.Set{sessionState: "Success"})}); err != nil {
|
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 {
|
if len(backupSessionList.Items) < 2 {
|
||||||
// Not enough backupSession to proceed
|
// Not enough backupSession to proceed
|
||||||
return ctrl.Result{}, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(backupSessionList.Items, func(i, j int) bool {
|
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
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user