Skip to content

Commit

Permalink
Local secure directory with appliance name
Browse files Browse the repository at this point in the history
Added appliance name to the local directory where secure backup
files are copyied. Easier secure backup of multiple appliances.

Fixed issue with refreshing the appliance filestore cache - when
performing secure backup for multiple appliance, copying files
to local filesystem failed.
  • Loading branch information
vvidovic-croz committed Aug 18, 2021
1 parent cf58037 commit efcc492
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"encoding/json"
"flag"
"fmt"
"os"
"os/user"
"strings"

"github.com/croz-ltd/confident"
"github.com/croz-ltd/dpcmder/help"
"github.com/croz-ltd/dpcmder/utils/logging"
"github.com/croz-ltd/dpcmder/utils/paths"
"github.com/howeyc/gopass"
"os"
"os/user"
"strings"
)

const (
Expand Down
67 changes: 37 additions & 30 deletions ui/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,44 +983,59 @@ loop:
certName := dialogSession.list[dialogSession.selectionIdx]
updateStatusf("Secure backup using cert '%v'...", certName)

exportDirName := "secure_backup_" + time.Now().Format("20060102150405")
exportDestPath := "temporary:/" + exportDirName
dpExportDirName := "secure_backup_" + time.Now().Format("20060102150405")
localExportDirName := applianceName + "_" + dpExportDirName
dpExportDestPath := "temporary:/" + dpExportDirName
toSide := m.OtherSide()
toViewConfig := m.ViewConfig(toSide)

toParentPath := toViewConfig.Path
logging.LogDebugf("ui/secureBackupCurrent(), certName: '%v', toParentPath '%v', exportDirName: '%v'",
certName, toParentPath, exportDirName)
destDirType, err := fileRepo.GetFileType(toViewConfig, toParentPath, exportDirName)
logging.LogDebugf("ui/secureBackupCurrent(), certName: '%v', toParentPath '%v', dpExportDirName: '%v', localExportDirName: '%v'",
certName, toParentPath, dpExportDirName, localExportDirName)
destDirType, err := fileRepo.GetFileType(toViewConfig, toParentPath, localExportDirName)
if err != nil {
return err
}
if destDirType != model.ItemNone {
return errs.Errorf("Secure backup directory '%v' already exists.", exportDirName)
return errs.Errorf("Local secure backup directory '%v' already exists.", localExportDirName)
}
_, err = fileRepo.CreateDir(toViewConfig, toParentPath, exportDirName)
_, err = fileRepo.CreateDir(toViewConfig, toParentPath, localExportDirName)
if err != nil {
return errs.Errorf("Can't create secure backup directory with name '%s' - '%v'.", exportDirName, err)
return errs.Errorf("Can't create local secure backup directory with name '%s' - '%v'.", localExportDirName, err)
}
updateStatusf("Secure backup directory '%s' created.", exportDirName)
updateStatusf("Local secure backup directory '%s' created.", localExportDirName)

showProgressDialogf("Secure DataPower appliance backup '%s'...", applianceName)
err = dp.Repo.SecureBackupAppliance(applianceName, certName, exportDestPath)
logging.LogDebugf("ui/secureBackupCurrent(), created backup at '%v'", exportDestPath)
err = dp.Repo.SecureBackupAppliance(applianceName, certName, dpExportDestPath)
logging.LogDebugf("ui/secureBackupCurrent(), created backup at '%v'", dpExportDestPath)
hideProgressDialog()
if err != nil {
return err
}

dpBackupDirConfig := model.ItemConfig{
dpTemporaryFilestoreConfig := model.ItemConfig{
Parent: nil,
Type: model.ItemDpFilestore,
Path: "temporary:",
Name: "temporary:",
DpAppliance: applianceName,
DpDomain: "default",
DpFilestore: "temporary:"}
dpBackupDirConfig := model.ItemConfig{
Parent: &dpTemporaryFilestoreConfig,
Type: model.ItemDirectory,
Path: exportDestPath,
Name: exportDirName,
Path: dpExportDestPath,
Name: dpExportDirName,
DpAppliance: applianceName,
DpDomain: "default",
DpFilestore: "temporary:"}
dpRepo.DpViewMode = model.DpFilestoreMode
// Refresh termporary: filestore (SOMA filestore is cached after we fetch
// it the first time).
_, err = dpRepo.GetList(&dpTemporaryFilestoreConfig)
if err != nil {
return err
}
secureBackupItems, err := dpRepo.GetList(&dpBackupDirConfig)
logging.LogDebugf("ui/secureBackupCurrent(), secureBackupItems: '%v'", secureBackupItems)
if err != nil {
Expand All @@ -1030,7 +1045,7 @@ loop:
showProgressDialog("Copying secure backup files from DataPower...")
defer hideProgressDialog()
fileViewBackupDirConfig := model.ItemConfig{Parent: toViewConfig,
Path: fileRepo.GetFilePath(toViewConfig.Path, exportDirName),
Path: fileRepo.GetFilePath(toViewConfig.Path, localExportDirName),
DpAppliance: toViewConfig.DpAppliance,
DpDomain: toViewConfig.DpDomain,
DpFilestore: toViewConfig.DpFilestore}
Expand All @@ -1043,27 +1058,19 @@ loop:
}
}

dpTemporaryFilestoreConfig := model.ItemConfig{
Parent: nil,
Type: model.ItemDpFilestore,
Path: "temporary:",
Name: "temporary:",
DpAppliance: applianceName,
DpDomain: "default",
DpFilestore: "temporary:"}
dpBackupDirItem := model.Item{Name: exportDirName, Config: &dpBackupDirConfig}
deleteItem(&dpRepo, &dpTemporaryFilestoreConfig, dpBackupDirItem, "n")
dpBackupDirItem := model.Item{Name: dpExportDirName, Config: &dpBackupDirConfig}
_, err = deleteItem(&dpRepo, &dpTemporaryFilestoreConfig, dpBackupDirItem, "n")
if err != nil {
return err
}
updateStatusf("Secure backup appliance directory deleted ('%v').", dpExportDirName)
updateStatusf("Secure backup copied to new local directory '%v'.", localExportDirName)
refreshView(m, model.Right)
updateStatusf("Secure backup copied to new directory '%v'.", exportDirName)
} else {
updateStatusf("Secure backup canceled...")
}

// err = exportAppliance(item.Config, toViewConfig, item.Name)
// updateStatusf("Secure backup...")

return nil

}

func diffCurrent(m *model.Model) error {
Expand Down

0 comments on commit efcc492

Please sign in to comment.