mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-11 22:10:11 +01:00
feat(backup,restore): adding validation for backup and restore
Added a schema validation for backup and restore CR. Also validating the server address in the backup/restore controller. Validating the server address as : ^([0-9]+.[0-9]+.[0-9]+.[0-9]+:[0-9]+)$ which is : <any number>.<any number>.<any number>.<any number>:<any number> Here we are validating just the format of the IP, not validating that IP should be correct which will be little more complex. In any case if IP is not correct, the zfs send will fail, so no need to do complex validation to validate the correct IP and port. Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
parent
5ea411ad05
commit
26968b5394
7 changed files with 62 additions and 15 deletions
|
|
@ -297,11 +297,14 @@ func buildVolumeResizeArgs(vol *apis.ZFSVolume) []string {
|
|||
}
|
||||
|
||||
// builldVolumeBackupArgs returns volume send command for sending the zfs volume
|
||||
func buildVolumeBackupArgs(bkp *apis.ZFSBackup, vol *apis.ZFSVolume) []string {
|
||||
func buildVolumeBackupArgs(bkp *apis.ZFSBackup, vol *apis.ZFSVolume) ([]string, error) {
|
||||
var ZFSVolArg []string
|
||||
backupDest := bkp.Spec.BackupDest
|
||||
|
||||
bkpAddr := strings.Split(backupDest, ":")
|
||||
if len(bkpAddr) != 2 {
|
||||
return ZFSVolArg, fmt.Errorf("zfs: invalid backup server address %s", backupDest)
|
||||
}
|
||||
|
||||
curSnap := vol.Spec.PoolName + "/" + vol.Name + "@" + bkp.Spec.SnapName
|
||||
|
||||
|
|
@ -319,24 +322,28 @@ func buildVolumeBackupArgs(bkp *apis.ZFSBackup, vol *apis.ZFSVolume) []string {
|
|||
|
||||
ZFSVolArg = append(ZFSVolArg, "-c", cmd)
|
||||
|
||||
return ZFSVolArg
|
||||
return ZFSVolArg, nil
|
||||
}
|
||||
|
||||
// builldVolumeRestoreArgs returns volume recv command for receiving the zfs volume
|
||||
func buildVolumeRestoreArgs(rstr *apis.ZFSRestore, vol *apis.ZFSVolume) []string {
|
||||
func buildVolumeRestoreArgs(rstr *apis.ZFSRestore, vol *apis.ZFSVolume) ([]string, error) {
|
||||
var ZFSVolArg []string
|
||||
restoreSrc := rstr.Spec.RestoreSrc
|
||||
|
||||
volume := vol.Spec.PoolName + "/" + vol.Name
|
||||
|
||||
rstrAddr := strings.Split(restoreSrc, ":")
|
||||
if len(rstrAddr) != 2 {
|
||||
return ZFSVolArg, fmt.Errorf("zfs: invalid restore server address %s", restoreSrc)
|
||||
}
|
||||
|
||||
source := "nc -w 3 " + rstrAddr[0] + " " + rstrAddr[1] + " | "
|
||||
|
||||
cmd := source + ZFSVolCmd + " " + ZFSRecvArg + " -F " + volume
|
||||
|
||||
ZFSVolArg = append(ZFSVolArg, "-c", cmd)
|
||||
|
||||
return ZFSVolArg
|
||||
return ZFSVolArg, nil
|
||||
}
|
||||
|
||||
// builldVolumeDestroyArgs returns volume destroy command along with attributes as a string array
|
||||
|
|
@ -692,7 +699,10 @@ func CreateBackup(bkp *apis.ZFSBackup) error {
|
|||
return err
|
||||
}
|
||||
|
||||
args := buildVolumeBackupArgs(bkp, vol)
|
||||
args, err := buildVolumeBackupArgs(bkp, vol)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd := exec.Command("bash", args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
||||
|
|
@ -741,7 +751,11 @@ func CreateRestore(rstr *apis.ZFSRestore) error {
|
|||
return err
|
||||
}
|
||||
volume := vol.Spec.PoolName + "/" + vol.Name
|
||||
args := buildVolumeRestoreArgs(rstr, vol)
|
||||
args, err := buildVolumeRestoreArgs(rstr, vol)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd := exec.Command("bash", args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue