snapshots #5
@ -21,6 +21,8 @@ type BackupSessionReconciler struct {
|
|||||||
func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||||
r.Log = log.FromContext(ctx)
|
r.Log = log.FromContext(ctx)
|
||||||
r.Context = ctx
|
r.Context = ctx
|
||||||
|
r.Namespace = req.NamespacedName.Namespace
|
||||||
|
r.Name = req.NamespacedName.Name
|
||||||
|
|
||||||
backupSession := formolv1alpha1.BackupSession{}
|
backupSession := formolv1alpha1.BackupSession{}
|
||||||
err := r.Get(ctx, req.NamespacedName, &backupSession)
|
err := r.Get(ctx, req.NamespacedName, &backupSession)
|
||||||
@ -47,7 +49,6 @@ func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
|||||||
}
|
}
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
r.Namespace = backupConf.Namespace
|
|
||||||
|
|
||||||
// we don't want a copy because we will modify and update it.
|
// we don't want a copy because we will modify and update it.
|
||||||
var target formolv1alpha1.Target
|
var target formolv1alpha1.Target
|
||||||
@ -96,7 +97,7 @@ func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
|||||||
newSessionState = formolv1alpha1.Waiting
|
newSessionState = formolv1alpha1.Waiting
|
||||||
switch target.BackupType {
|
switch target.BackupType {
|
||||||
case formolv1alpha1.JobKind:
|
case formolv1alpha1.JobKind:
|
||||||
if backupResult, err := r.backupJob(backupSession.Name, target); err != nil {
|
if backupResult, err := r.backupJob(target); err != nil {
|
||||||
r.Log.Error(err, "unable to run backup job", "target", targetName)
|
r.Log.Error(err, "unable to run backup job", "target", targetName)
|
||||||
newSessionState = formolv1alpha1.Failure
|
newSessionState = formolv1alpha1.Failure
|
||||||
} else {
|
} else {
|
||||||
@ -106,7 +107,7 @@ func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
|||||||
}
|
}
|
||||||
case formolv1alpha1.OnlineKind:
|
case formolv1alpha1.OnlineKind:
|
||||||
backupPaths := strings.Split(os.Getenv(formolv1alpha1.BACKUP_PATHS), string(os.PathListSeparator))
|
backupPaths := strings.Split(os.Getenv(formolv1alpha1.BACKUP_PATHS), string(os.PathListSeparator))
|
||||||
if backupResult, result := r.backupPaths(backupSession.Name, backupPaths); result != nil {
|
if backupResult, result := r.backupPaths(backupPaths); result != nil {
|
||||||
r.Log.Error(result, "unable to backup paths", "target name", targetName, "paths", backupPaths)
|
r.Log.Error(result, "unable to backup paths", "target name", targetName, "paths", backupPaths)
|
||||||
newSessionState = formolv1alpha1.Failure
|
newSessionState = formolv1alpha1.Failure
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -23,13 +23,13 @@ type BackupResult struct {
|
|||||||
Duration float64
|
Duration float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *BackupSessionReconciler) backupPaths(tag string, paths []string) (result BackupResult, err error) {
|
func (r *BackupSessionReconciler) backupPaths(paths []string) (result BackupResult, err error) {
|
||||||
if err = r.CheckRepo(); err != nil {
|
if err = r.CheckRepo(); err != nil {
|
||||||
r.Log.Error(err, "unable to setup repo", "repo", os.Getenv(formolv1alpha1.RESTIC_REPOSITORY))
|
r.Log.Error(err, "unable to setup repo", "repo", os.Getenv(formolv1alpha1.RESTIC_REPOSITORY))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.Log.V(0).Info("backing up paths", "paths", paths)
|
r.Log.V(0).Info("backing up paths", "paths", paths)
|
||||||
cmd := exec.Command(RESTIC_EXEC, append([]string{"backup", "--json", "--tag", tag}, paths...)...)
|
cmd := exec.Command(RESTIC_EXEC, append([]string{"backup", "--json", "--tag", r.Name}, paths...)...)
|
||||||
stdout, _ := cmd.StdoutPipe()
|
stdout, _ := cmd.StdoutPipe()
|
||||||
stderr, _ := cmd.StderrPipe()
|
stderr, _ := cmd.StderrPipe()
|
||||||
_ = cmd.Start()
|
_ = cmd.Start()
|
||||||
@ -55,7 +55,7 @@ func (r *BackupSessionReconciler) backupPaths(tag string, paths []string) (resul
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *BackupSessionReconciler) backupJob(tag string, target formolv1alpha1.Target) (result BackupResult, err error) {
|
func (r *BackupSessionReconciler) backupJob(target formolv1alpha1.Target) (result BackupResult, err error) {
|
||||||
paths := []string{}
|
paths := []string{}
|
||||||
for _, container := range target.Containers {
|
for _, container := range target.Containers {
|
||||||
for _, job := range container.Job {
|
for _, job := range container.Job {
|
||||||
@ -75,7 +75,7 @@ func (r *BackupSessionReconciler) backupJob(tag string, target formolv1alpha1.Ta
|
|||||||
paths = append(paths, container.SharePath)
|
paths = append(paths, container.SharePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result, err = r.backupPaths(tag, paths)
|
result, err = r.backupPaths(paths)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,8 @@ type RestoreSessionReconciler struct {
|
|||||||
func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||||
r.Log = log.FromContext(ctx)
|
r.Log = log.FromContext(ctx)
|
||||||
r.Context = ctx
|
r.Context = ctx
|
||||||
|
r.Namespace = req.NamespacedName.Namespace
|
||||||
|
r.Name = req.NamespacedName.Name
|
||||||
|
|
||||||
restoreSession := formolv1alpha1.RestoreSession{}
|
restoreSession := formolv1alpha1.RestoreSession{}
|
||||||
err := r.Get(r.Context, req.NamespacedName, &restoreSession)
|
err := r.Get(r.Context, req.NamespacedName, &restoreSession)
|
||||||
@ -49,7 +51,6 @@ func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
|
|||||||
}
|
}
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
r.Namespace = backupConf.Namespace
|
|
||||||
r.backupConf = backupConf
|
r.backupConf = backupConf
|
||||||
|
|
||||||
// we don't want a copy because we will modify and update it.
|
// we don't want a copy because we will modify and update it.
|
||||||
|
|||||||
@ -27,6 +27,7 @@ type Session struct {
|
|||||||
Scheme *runtime.Scheme
|
Scheme *runtime.Scheme
|
||||||
context.Context
|
context.Context
|
||||||
Namespace string
|
Namespace string
|
||||||
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user