-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implementation of the Backup service (#7)
Signed-off-by: Leonardo Cecchi <[email protected]> Signed-off-by: Armando Ruocco <[email protected]> Co-authored-by: Armando Ruocco <[email protected]>
- Loading branch information
1 parent
c3cda12
commit fb21225
Showing
25 changed files
with
915 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package backup | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/cloudnative-pg/cnpg-i/pkg/backup" | ||
|
||
"github.com/cloudnative-pg/plugin-pvc-backup/internal/backup/executor" | ||
"github.com/cloudnative-pg/plugin-pvc-backup/internal/backup/storage" | ||
"github.com/cloudnative-pg/plugin-pvc-backup/pkg/logging" | ||
"github.com/cloudnative-pg/plugin-pvc-backup/pkg/metadata" | ||
"github.com/cloudnative-pg/plugin-pvc-backup/pkg/pluginhelper" | ||
) | ||
|
||
// Implementation is the implementation of the identity service | ||
type Implementation struct { | ||
backup.BackupServer | ||
} | ||
|
||
// GetCapabilities gets the capabilities of the Backup service | ||
func (Implementation) GetCapabilities( | ||
context.Context, | ||
*backup.BackupCapabilitiesRequest, | ||
) (*backup.BackupCapabilitiesResult, error) { | ||
return &backup.BackupCapabilitiesResult{ | ||
Capabilities: []*backup.BackupCapability{ | ||
{ | ||
Type: &backup.BackupCapability_Rpc{ | ||
Rpc: &backup.BackupCapability_RPC{ | ||
Type: backup.BackupCapability_RPC_TYPE_BACKUP, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, nil | ||
} | ||
|
||
// Backup take a physical backup using Kopia | ||
func (Implementation) Backup( | ||
ctx context.Context, | ||
request *backup.BackupRequest, | ||
) (*backup.BackupResult, error) { | ||
contextLogger := logging.FromContext(ctx) | ||
|
||
helper, err := pluginhelper.NewDataBuilder(metadata.Data.Name, request.ClusterDefinition).Build() | ||
if err != nil { | ||
contextLogger.Error(err, "Error while decoding cluster definition from CNPG") | ||
return nil, err | ||
} | ||
|
||
backupObject, err := helper.DecodeBackup(request.BackupDefinition) | ||
if err != nil { | ||
contextLogger.Error(err, "Error while decoding backup definition from CNPG") | ||
return nil, err | ||
} | ||
|
||
cluster := helper.GetCluster() | ||
rep, err := executor.NewRepository( | ||
ctx, | ||
storage.GetBasePath(cluster.Name), | ||
storage.GetKopiaConfigFilePath(cluster.Name), | ||
storage.GetKopiaCacheDirectory(cluster.Name), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
exec := executor.NewLocalExecutor( | ||
cluster, | ||
backupObject, | ||
rep, | ||
) | ||
|
||
startedAt := time.Now() | ||
backupInfo, err := exec.TakeBackup(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &backup.BackupResult{ | ||
BackupId: backupInfo.BackupName, | ||
BackupName: backupInfo.BackupName, | ||
StartedAt: startedAt.Unix(), | ||
StoppedAt: time.Now().Unix(), | ||
BeginWal: exec.GetBeginWal(), | ||
EndWal: exec.GetEndWal(), | ||
BeginLsn: string(backupInfo.BeginLSN), | ||
EndLsn: string(backupInfo.EndLSN), | ||
BackupLabelFile: backupInfo.LabelFile, | ||
TablespaceMapFile: backupInfo.SpcmapFile, | ||
Online: true, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package backup contain the implementation of the Backup service | ||
package backup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package executor | ||
|
||
const podIP = "127.0.0.1" |
Oops, something went wrong.