Skip to content

Commit

Permalink
allow snapshots to be provided for rollback
Browse files Browse the repository at this point in the history
Signed-off-by: pault84 <[email protected]>
  • Loading branch information
pault84 committed Jun 11, 2021
1 parent 97cb694 commit 01b56d7
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions cmd/3ncryptor/3ncryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ func newRollbackCommand() *cobra.Command {
Use: "rollback",
Short: "Start rollback",
Run: func(c *cobra.Command, args []string) {
var (
volumes []*api.Volume
err error
)

if len(volume_ids) == 0 && len(namespace) == 0 {
logrus.Errorf("namespace is required")
os.Exit(1)
Expand All @@ -296,11 +301,6 @@ func newRollbackCommand() *cobra.Command {
return
}

var (
volumes []*api.Volume
err error
)

if len(volume_ids) != 0 {
volumes, err = inspectVolumes(strings.Split(volume_ids, ","))
logrus.Infof("Inspect")
Expand All @@ -322,11 +322,21 @@ func newRollbackCommand() *cobra.Command {
origVolName string = vol.Locator.Name
)

if !strings.Contains(vol.Locator.Name, "-encryptorsnap") && !strings.Contains(vol.Locator.Name, "-encrypted") {
logrus.Infof("Rolling back volume: %v", vol.Locator.Name)
if len(volume_ids) == 0 && strings.Contains(vol.Locator.Name, "-encryptorsnap") && strings.Contains(vol.Locator.Name, "-encrypted") {
continue
}

snapVol = nil
snaps, err := inspectVolumes([]string{vol.Locator.Name + "-encryptorsnap"})
if strings.Contains(vol.Locator.Name, "-encryptorsnap") {
origVolName = strings.Split(vol.Locator.Name, "-encryptorsnap")[0]
} else if strings.Contains(vol.Locator.Name, "-encrypted") {
origVolName = strings.Split(vol.Locator.Name, "-encrypted")[0]
}

logrus.Infof("Rolling back volume: %v", origVolName)

snapVol = nil
if !vol.IsSnapshot() {
snaps, err := inspectVolumes([]string{origVolName + "-encryptorsnap"})
if err != nil {
logrus.Errorf("Failed to find the encryptor snap for %v", origVolName)
return
Expand All @@ -335,32 +345,32 @@ func newRollbackCommand() *cobra.Command {
if len(snaps) != 0 {
snapVol = snaps[0]
}
}
encVol = nil
encvols, err := inspectVolumes([]string{origVolName + "-encrypted"})
if err != nil {
logrus.Errorf("Failed to find the encrypted volume for: %v", origVolName)
return
}

encVol = nil
encvols, err := inspectVolumes([]string{vol.Locator.Name + "-encrypted"})
if len(encvols) != 0 {
encVol = encvols[0]
}

if snapVol != nil {
logrus.Infof("Deleting original volume")
err := deleteVol(vol)
if err != nil {
logrus.Errorf("Failed to find the encrypted volume for: %v", origVolName)
logrus.Errorf("Failed to delete original volume")
return
}

if len(encvols) != 0 {
encVol = encvols[0]
}

if snapVol != nil {
logrus.Infof("Deleting original volume")
err := deleteVol(vol)
if err != nil {
logrus.Errorf("Failed to delete original volume")
return
}

err = rollBack(snapVol, encVol, origVolName)
if err != nil {
logrus.Errorf("Failed to rollback volume %v", err)
}
err = rollBack(snapVol, encVol, origVolName)
if err != nil {
logrus.Errorf("Failed to rollback volume %v", err)
}
}

}
},
}
Expand Down

0 comments on commit 01b56d7

Please sign in to comment.