Skip to content

Commit 1e7c8ce

Browse files
authored
Make backups transfer with servers (#155)
* Make backups transfer with servers * Remove extra line + fix Minor grammar issue in comment
1 parent de3ea74 commit 1e7c8ce

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

router/router_server_transfer.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import (
1818

1919
// Data passed over to initiate a server transfer.
2020
type serverTransferRequest struct {
21-
URL string `binding:"required" json:"url"`
22-
Token string `binding:"required" json:"token"`
23-
Server installer.ServerDetails `json:"server"`
21+
URL string `binding:"required" json:"url"`
22+
Token string `binding:"required" json:"token"`
23+
Backups []string `json:"backups"`
24+
Server installer.ServerDetails `json:"server"`
2425
}
2526

2627
// postServerTransfer handles the start of a transfer for a server.
@@ -80,7 +81,7 @@ func postServerTransfer(c *gin.Context) {
8081
go func() {
8182
defer transfer.Outgoing().Remove(trnsfr)
8283

83-
if _, err := trnsfr.PushArchiveToTarget(data.URL, data.Token); err != nil {
84+
if _, err := trnsfr.PushArchiveToTarget(data.URL, data.Token, data.Backups); err != nil {
8485
notifyPanelOfFailure()
8586

8687
if err == context.Canceled {

server/transfer/archive.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (t *Transfer) Archive() (*Archive, error) {
3535
}
3636

3737
func (a *Archive) StreamBackups(ctx context.Context, mp *multipart.Writer) error {
38+
// In theory this can't happen as this function is only called if there is at least 1 backup but just to be sure
3839
if len(a.transfer.BackupUUIDs) == 0 {
3940
a.transfer.Log().Debug("no backups specified for transfer")
4041
return nil

server/transfer/source.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// PushArchiveToTarget POSTs the archive to the target node and returns the
1616
// response body.
17-
func (t *Transfer) PushArchiveToTarget(url, token string) ([]byte, error) {
17+
func (t *Transfer) PushArchiveToTarget(url, token string, backups []string) ([]byte, error) {
1818
ctx, cancel := context.WithCancel(t.ctx)
1919
defer cancel()
2020

@@ -123,7 +123,8 @@ func (t *Transfer) PushArchiveToTarget(url, token string) ([]byte, error) {
123123
errChan <- errors.New("failed to stream main archive checksum")
124124
return
125125
}
126-
126+
// Store the UUID of the backups we want to transfer in the transfer struct
127+
t.BackupUUIDs = backups
127128
if len(t.BackupUUIDs) > 0 {
128129
t.SendMessage(fmt.Sprintf("Streaming %d backup files to destination...", len(t.BackupUUIDs)))
129130
if err := a.StreamBackups(ctx, mp); err != nil {

0 commit comments

Comments
 (0)