Skip to content

Commit

Permalink
remove snapshot parameter and add support for localbackup
Browse files Browse the repository at this point in the history
Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 committed Aug 15, 2020
1 parent c6f0823 commit 97976fe
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 48 deletions.
19 changes: 14 additions & 5 deletions deploy/operators/centos7/zfs-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,19 @@ metadata:
creationTimestamp: null
name: zfsbackups.zfs.openebs.io
spec:
additionalPrinterColumns:
- JSONPath: .spec.prevSnapName
description: Previous snapshot for backup
name: PrevSnap
type: string
- JSONPath: .status
description: Backup status
name: Status
type: string
- JSONPath: .metadata.creationTimestamp
description: Age of the volume
name: Age
type: date
group: zfs.openebs.io
names:
kind: ZFSBackup
Expand All @@ -859,6 +872,7 @@ spec:
singular: zfsbackup
preserveUnknownFields: false
scope: Namespaced
subresources: {}
validation:
openAPIV3Schema:
description: ZFSBackup describes a zfs backup resource created as a custom resource
Expand Down Expand Up @@ -890,10 +904,6 @@ spec:
prevSnapName:
description: PrevSnapName is the last completed-backup's snapshot name
type: string
snapName:
description: SnapName is a name of the current backup snapshot
minLength: 1
type: string
volumeName:
description: VolumeName is a name of the volume for which this backup
is destined
Expand All @@ -902,7 +912,6 @@ spec:
required:
- backupDest
- ownerNodeID
- snapName
- volumeName
type: object
status:
Expand Down
19 changes: 14 additions & 5 deletions deploy/operators/centos8/zfs-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,19 @@ metadata:
creationTimestamp: null
name: zfsbackups.zfs.openebs.io
spec:
additionalPrinterColumns:
- JSONPath: .spec.prevSnapName
description: Previous snapshot for backup
name: PrevSnap
type: string
- JSONPath: .status
description: Backup status
name: Status
type: string
- JSONPath: .metadata.creationTimestamp
description: Age of the volume
name: Age
type: date
group: zfs.openebs.io
names:
kind: ZFSBackup
Expand All @@ -859,6 +872,7 @@ spec:
singular: zfsbackup
preserveUnknownFields: false
scope: Namespaced
subresources: {}
validation:
openAPIV3Schema:
description: ZFSBackup describes a zfs backup resource created as a custom resource
Expand Down Expand Up @@ -890,10 +904,6 @@ spec:
prevSnapName:
description: PrevSnapName is the last completed-backup's snapshot name
type: string
snapName:
description: SnapName is a name of the current backup snapshot
minLength: 1
type: string
volumeName:
description: VolumeName is a name of the volume for which this backup
is destined
Expand All @@ -902,7 +912,6 @@ spec:
required:
- backupDest
- ownerNodeID
- snapName
- volumeName
type: object
status:
Expand Down
19 changes: 14 additions & 5 deletions deploy/yamls/zfsbackup-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ metadata:
creationTimestamp: null
name: zfsbackups.zfs.openebs.io
spec:
additionalPrinterColumns:
- JSONPath: .spec.prevSnapName
description: Previous snapshot for backup
name: PrevSnap
type: string
- JSONPath: .status
description: Backup status
name: Status
type: string
- JSONPath: .metadata.creationTimestamp
description: Age of the volume
name: Age
type: date
group: zfs.openebs.io
names:
kind: ZFSBackup
Expand All @@ -29,6 +42,7 @@ spec:
singular: zfsbackup
preserveUnknownFields: false
scope: Namespaced
subresources: {}
validation:
openAPIV3Schema:
description: ZFSBackup describes a zfs backup resource created as a custom resource
Expand Down Expand Up @@ -60,10 +74,6 @@ spec:
prevSnapName:
description: PrevSnapName is the last completed-backup's snapshot name
type: string
snapName:
description: SnapName is a name of the current backup snapshot
minLength: 1
type: string
volumeName:
description: VolumeName is a name of the volume for which this backup
is destined
Expand All @@ -72,7 +82,6 @@ spec:
required:
- backupDest
- ownerNodeID
- snapName
- volumeName
type: object
status:
Expand Down
19 changes: 14 additions & 5 deletions deploy/zfs-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,19 @@ metadata:
creationTimestamp: null
name: zfsbackups.zfs.openebs.io
spec:
additionalPrinterColumns:
- JSONPath: .spec.prevSnapName
description: Previous snapshot for backup
name: PrevSnap
type: string
- JSONPath: .status
description: Backup status
name: Status
type: string
- JSONPath: .metadata.creationTimestamp
description: Age of the volume
name: Age
type: date
group: zfs.openebs.io
names:
kind: ZFSBackup
Expand All @@ -859,6 +872,7 @@ spec:
singular: zfsbackup
preserveUnknownFields: false
scope: Namespaced
subresources: {}
validation:
openAPIV3Schema:
description: ZFSBackup describes a zfs backup resource created as a custom resource
Expand Down Expand Up @@ -890,10 +904,6 @@ spec:
prevSnapName:
description: PrevSnapName is the last completed-backup's snapshot name
type: string
snapName:
description: SnapName is a name of the current backup snapshot
minLength: 1
type: string
volumeName:
description: VolumeName is a name of the volume for which this backup
is destined
Expand All @@ -902,7 +912,6 @@ spec:
required:
- backupDest
- ownerNodeID
- snapName
- volumeName
type: object
status:
Expand Down
8 changes: 3 additions & 5 deletions pkg/apis/openebs.io/zfs/v1/zfsbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:resource:scope=Namespaced,shortName=zb
// +kubebuilder:printcolumn:name="PrevSnap",type=string,JSONPath=`.spec.prevSnapName`,description="Previous snapshot for backup"
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status`,description="Backup status"
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="Age of the volume"
type ZFSBackup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -47,11 +50,6 @@ type ZFSBackupSpec struct {
// +kubebuilder:validation:MinLength=1
OwnerNodeID string `json:"ownerNodeID"`

// SnapName is a name of the current backup snapshot
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
SnapName string `json:"snapName"`

// PrevSnapName is the last completed-backup's snapshot name
PrevSnapName string `json:"prevSnapName,omitempty"`

Expand Down
21 changes: 6 additions & 15 deletions pkg/builder/bkpbuilder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ func (b *Builder) WithName(name string) *Builder {
return b
}

// WithPrevSnap sets the previous snapshot for ZFSBackup
func (b *Builder) WithPrevSnap(snap string) *Builder {
b.bkp.Object.Spec.PrevSnapName = snap
return b
}

// WithVolume sets the volume name of ZFSBackup
func (b *Builder) WithVolume(volume string) *Builder {
if volume == "" {
Expand Down Expand Up @@ -114,21 +120,6 @@ func (b *Builder) WithNode(node string) *Builder {
return b
}

// WithSnapshot sets the snapshot to create the ZFSBackup
func (b *Builder) WithSnapshot(snap string) *Builder {
if snap == "" {
b.errs = append(
b.errs,
errors.New(
"failed to build bkp object: missing snap name",
),
)
return b
}
b.bkp.Object.Spec.SnapName = snap
return b
}

// WithStatus sets the status of the Backup progress
func (b *Builder) WithStatus(status apis.ZFSBackupStatus) *Builder {
if status == "" {
Expand Down
10 changes: 5 additions & 5 deletions pkg/mgmt/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ func (c *BkpController) syncBkp(bkp *apis.ZFSBackup) error {
if bkp.Status == apis.BKPZFSStatusInit {
err = zfs.CreateBackup(bkp)
if err == nil {
klog.Infof("backup %s done %s@%s", bkp.Name, bkp.Spec.VolumeName, bkp.Spec.SnapName)
klog.Infof("backup %s done %s@%s prevsnap [%s]", bkp.Name, bkp.Spec.VolumeName, bkp.Name, bkp.Spec.PrevSnapName)
zfs.UpdateBkpInfo(bkp, apis.BKPZFSStatusDone)
} else {
klog.Errorf("backup %s failed %s@%s", bkp.Name, bkp.Spec.VolumeName, bkp.Spec.SnapName)
klog.Errorf("backup %s failed %s@%s", bkp.Name, bkp.Spec.VolumeName, bkp.Name)
zfs.UpdateBkpInfo(bkp, apis.BKPZFSStatusFailed)
}
}
Expand All @@ -109,7 +109,7 @@ func (c *BkpController) addBkp(obj interface{}) {
if zfs.NodeID != bkp.Spec.OwnerNodeID {
return
}
klog.Infof("Got add event for Bkp %s@%s", bkp.Spec.VolumeName, bkp.Spec.SnapName)
klog.Infof("Got add event for Bkp %s snap %s@%s", bkp.Name, bkp.Spec.VolumeName, bkp.Name)
c.enqueueBkp(bkp)
}

Expand All @@ -127,7 +127,7 @@ func (c *BkpController) updateBkp(oldObj, newObj interface{}) {
}

if c.isDeletionCandidate(newBkp) {
klog.Infof("Got update event for Bkp %s@%s", newBkp.Spec.VolumeName, newBkp.Spec.SnapName)
klog.Infof("Got update event for Bkp %s snap %s@%s", newBkp.Name, newBkp.Spec.VolumeName, newBkp.Name)
c.enqueueBkp(newBkp)
}
}
Expand All @@ -152,7 +152,7 @@ func (c *BkpController) deleteBkp(obj interface{}) {
return
}

klog.Infof("Got delete event for Bkp %s snap %s@%s", bkp.Name, bkp.Spec.VolumeName, bkp.Spec.SnapName)
klog.Infof("Got delete event for Bkp %s snap %s@%s", bkp.Name, bkp.Spec.VolumeName, bkp.Name)
c.enqueueBkp(bkp)
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/zfs/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const (
ZFSStatusPending string = "Pending"
// ZFSStatusReady shows object has been processed
ZFSStatusReady string = "Ready"
// ZFSLocalBackup sspecifies it is a local backup
ZFSLocalBackup string = "local"
)

var (
Expand Down
11 changes: 8 additions & 3 deletions pkg/zfs/zfs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func buildVolumeBackupArgs(bkp *apis.ZFSBackup, vol *apis.ZFSVolume) []string {

bkpAddr := strings.Split(backupDest, ":")

curSnap := vol.Spec.PoolName + "/" + vol.Name + "@" + bkp.Spec.SnapName
curSnap := vol.Spec.PoolName + "/" + vol.Name + "@" + bkp.Name

remote := " | nc -w 3 " + bkpAddr[0] + " " + bkpAddr[1]

Expand Down Expand Up @@ -678,7 +678,7 @@ func CreateBackup(bkp *apis.ZFSBackup) error {

/* create the snapshot for the backup */
snap := &apis.ZFSSnapshot{}
snap.Name = bkp.Spec.SnapName
snap.Name = bkp.Name
snap.Spec.PoolName = vol.Spec.PoolName
snap.Labels = map[string]string{ZFSVolKey: vol.Name}

Expand All @@ -691,6 +691,11 @@ func CreateBackup(bkp *apis.ZFSBackup) error {
return err
}

// if it is local backup request, return after taking the snapshot
if bkp.Spec.BackupDest == ZFSLocalBackup {
return nil
}

args := buildVolumeBackupArgs(bkp, vol)
cmd := exec.Command("bash", args...)
out, err := cmd.CombinedOutput()
Expand All @@ -715,7 +720,7 @@ func DestoryBackup(bkp *apis.ZFSBackup) error {

/* create the snapshot for the backup */
snap := &apis.ZFSSnapshot{}
snap.Name = bkp.Spec.SnapName
snap.Name = bkp.Name
snap.Spec.PoolName = vol.Spec.PoolName
snap.Labels = map[string]string{ZFSVolKey: vol.Name}

Expand Down

0 comments on commit 97976fe

Please sign in to comment.