Compare commits

...

2 Commits

8 changed files with 22 additions and 15 deletions

View File

@ -29,11 +29,14 @@ var createBackupSessionCmd = &cobra.Command{
var backupCmd = &cobra.Command{
Use: "backup",
Short: "Backup paths",
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
backupSessionName, _ := cmd.Flags().GetString("name")
backupSessionNamespace, _ := cmd.Flags().GetString("namespace")
targetName, _ := cmd.Flags().GetString("target-name")
standalone.BackupPaths(backupSessionName, backupSessionNamespace, targetName, args...)
if err := standalone.BackupPaths(backupSessionName, backupSessionNamespace, targetName, args...); err != nil {
return err
}
return nil
},
}
@ -78,8 +81,9 @@ var deleteSnapshotCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
name, _ := cmd.Flags().GetString("name")
namespace, _ := cmd.Flags().GetString("namespace")
targetName, _ := cmd.Flags().GetString("target-name")
snapshotId, _ := cmd.Flags().GetString("snapshot-id")
standalone.DeleteSnapshot(namespace, name, snapshotId)
standalone.DeleteSnapshot(namespace, name, targetName, snapshotId)
},
}
@ -135,7 +139,9 @@ func init() {
deleteSnapshotCmd.Flags().String("snapshot-id", "", "The snapshot id to delete")
deleteSnapshotCmd.Flags().String("namespace", "", "The namespace of the BackupConfiguration containing the information about the backup.")
deleteSnapshotCmd.Flags().String("name", "", "The name of the BackupConfiguration containing the information about the backup.")
deleteSnapshotCmd.Flags().String("target-name", "", "The name of the backup target.")
deleteSnapshotCmd.MarkFlagRequired("snapshot-id")
deleteSnapshotCmd.MarkFlagRequired("namespace")
deleteSnapshotCmd.MarkFlagRequired("name")
deleteSnapshotCmd.MarkFlagRequired("target-name")
}

View File

@ -72,7 +72,7 @@ func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
// Do preliminary checks with the repository
if err = r.SetResticEnv(backupConf); err != nil {
if err = r.SetResticEnv(backupConf, target.TargetName); err != nil {
r.Log.Error(err, "unable to set restic env")
return ctrl.Result{}, err
}

View File

@ -71,7 +71,7 @@ func (r *BackupSessionReconciler) backupSnapshot(target formolv1alpha1.Target) (
sidecar := formolv1alpha1.GetSidecar(r.backupConf, target)
sidecar.Args = append([]string{"backupsession", "backup", "--namespace", r.Namespace, "--name", r.Name, "--target-name", target.TargetName}, paths...)
sidecar.VolumeMounts = vms
if env, err := r.getResticEnv(r.backupConf); err != nil {
if env, err := r.getResticEnv(r.backupConf, target.TargetName); err != nil {
r.Log.Error(err, "unable to get restic env")
return err
} else {

View File

@ -69,7 +69,7 @@ func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}
// Do preliminary checks with the repository
if err = r.SetResticEnv(backupConf); err != nil {
if err = r.SetResticEnv(backupConf, target.TargetName); err != nil {
r.Log.Error(err, "unable to set restic env")
return ctrl.Result{}, err
}

View File

@ -34,7 +34,7 @@ func (r *RestoreSessionReconciler) restoreInitContainer(target formolv1alpha1.Ta
for i, _ := range initContainer.VolumeMounts {
initContainer.VolumeMounts[i].ReadOnly = false
}
if env, err := r.getResticEnv(r.backupConf); err != nil {
if env, err := r.getResticEnv(r.backupConf, target.TargetName); err != nil {
r.Log.Error(err, "unable to get restic env")
return err
} else {

View File

@ -40,7 +40,7 @@ const (
RESTIC_EXEC = "/usr/bin/restic"
)
func (s Session) getResticEnv(backupConf formolv1alpha1.BackupConfiguration) (envs []corev1.EnvVar, err error) {
func (s Session) getResticEnv(backupConf formolv1alpha1.BackupConfiguration, targetName string) (envs []corev1.EnvVar, err error) {
repo := formolv1alpha1.Repo{}
if err = s.Get(s.Context, client.ObjectKey{
Namespace: backupConf.Namespace,
@ -52,11 +52,12 @@ func (s Session) getResticEnv(backupConf formolv1alpha1.BackupConfiguration) (en
if repo.Spec.Backend.S3 != nil {
envs = append(envs, corev1.EnvVar{
Name: formolv1alpha1.RESTIC_REPOSITORY,
Value: fmt.Sprintf("s3:http://%s/%s/%s-%s",
Value: fmt.Sprintf("s3:http://%s/%s/%s-%s/%s",
repo.Spec.Backend.S3.Server,
repo.Spec.Backend.S3.Bucket,
strings.ToUpper(backupConf.Namespace),
strings.ToLower(backupConf.Name)),
strings.ToLower(backupConf.Name),
targetName),
})
data := s.getSecretData(repo.Spec.RepositorySecrets)
@ -76,8 +77,8 @@ func (s Session) getResticEnv(backupConf formolv1alpha1.BackupConfiguration) (en
return
}
func (s Session) SetResticEnv(backupConf formolv1alpha1.BackupConfiguration) error {
envs, err := s.getResticEnv(backupConf)
func (s Session) SetResticEnv(backupConf formolv1alpha1.BackupConfiguration, targetName string) error {
envs, err := s.getResticEnv(backupConf, targetName)
for _, env := range envs {
os.Setenv(env.Name, env.Value)
}

2
formol

@ -1 +1 @@
Subproject commit 92ea7f38729eebebd3cabff4a391bdb878c4e387
Subproject commit 6f150cc36de7f879e2ddd89d126de84b77af0651

View File

@ -199,7 +199,7 @@ func CreateBackupSession(ref corev1.ObjectReference) {
}
}
func DeleteSnapshot(namespace string, name string, snapshotId string) {
func DeleteSnapshot(namespace string, name string, targetName string, snapshotId string) {
log := session.Log.WithName("DeleteSnapshot")
session.Namespace = namespace
backupConf := formolv1alpha1.BackupConfiguration{}
@ -210,7 +210,7 @@ func DeleteSnapshot(namespace string, name string, snapshotId string) {
log.Error(err, "unable to get the BackupConf")
return
}
if err := session.SetResticEnv(backupConf); err != nil {
if err := session.SetResticEnv(backupConf, targetName); err != nil {
log.Error(err, "unable to set the restic env")
return
}