Skip to content

Commit 83208ee

Browse files
authored
GT-589 Backup API support in V2 (#603)
1 parent e0f43e5 commit 83208ee

File tree

8 files changed

+788
-10
lines changed

8 files changed

+788
-10
lines changed

v2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Switch to Go 1.21.8
1717
- multi_delimiter analyzer support
1818
- Wildcard analyzer support
19+
- Backup API support
1920

2021

2122
## [2.0.3](https://github.com/arangodb/go-driver/tree/v2.0.3) (2023-10-31)

v2/arangodb/client_admin.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -43,12 +43,10 @@ type ClientAdmin interface {
4343
SetServerMode(ctx context.Context, mode ServerMode) error
4444
}
4545

46-
type ClientAdminBackup interface {
47-
}
48-
4946
type ClientAdminLog interface {
5047
// GetLogLevels returns log levels for topics.
5148
GetLogLevels(ctx context.Context, opts *LogLevelsGetOptions) (LogLevels, error)
49+
5250
// SetLogLevels sets log levels for a given topics.
5351
SetLogLevels(ctx context.Context, logLevels LogLevels, opts *LogLevelsSetOptions) error
5452
}

v2/arangodb/client_admin_backup.go

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package arangodb
22+
23+
import (
24+
"context"
25+
"time"
26+
)
27+
28+
type ClientAdminBackup interface {
29+
// BackupCreate creates a new backup and returns its id
30+
BackupCreate(ctx context.Context, opt *BackupCreateOptions) (BackupResponse, error)
31+
32+
// BackupRestore restores the backup with given id
33+
BackupRestore(ctx context.Context, id string) (BackupRestoreResponse, error)
34+
35+
// BackupDelete deletes the backup with given id
36+
BackupDelete(ctx context.Context, id string) error
37+
38+
// BackupList returns meta data about some/all backups available
39+
BackupList(ctx context.Context, opt *BackupListOptions) (ListBackupsResponse, error)
40+
41+
// BackupUpload triggers an upload of backup into the remote repository using the given config
42+
BackupUpload(ctx context.Context, backupId string, remoteRepository string, config interface{}) (TransferMonitor, error)
43+
44+
// BackupDownload triggers a download of backup into the remote repository using the given config
45+
BackupDownload(ctx context.Context, backupId string, remoteRepository string, config interface{}) (TransferMonitor, error)
46+
}
47+
48+
type TransferMonitor interface {
49+
// Progress returns the progress of the transfer (upload/download)
50+
Progress(ctx context.Context) (BackupTransferProgressResponse, error)
51+
52+
// Abort the transfer (upload/download)
53+
Abort(ctx context.Context) error
54+
}
55+
56+
type BackupCreateOptions struct {
57+
// The label for this backup.
58+
// The label is used together with a timestamp string create a unique backup identifier, <timestamp>_<label>.
59+
// Default: If omitted or empty, a UUID will be generated.
60+
Label string `json:"label,omitempty"`
61+
62+
// The time in seconds that the operation tries to get a consistent snapshot. The default is 120 seconds.
63+
Timeout *uint `json:"timeout,omitempty"`
64+
65+
// If set to `true` and no global transaction lock can be acquired within the
66+
// given timeout, a possibly inconsistent backup is taken.
67+
AllowInconsistent *bool `json:"allowInconsistent,omitempty"`
68+
69+
// (Enterprise Edition cluster only.) If set to `true` and no global transaction lock can be acquired within the
70+
// given timeout, all running transactions are forcefully aborted to ensure that a consistent backup can be created.
71+
Force *bool `json:"force,omitempty"`
72+
}
73+
74+
type BackupResponse struct {
75+
ID string `json:"id,omitempty"`
76+
PotentiallyInconsistent bool `json:"potentiallyInconsistent,omitempty"`
77+
NumberOfFiles uint `json:"nrFiles,omitempty"`
78+
NumberOfDBServers uint `json:"nrDBServers,omitempty"`
79+
SizeInBytes uint64 `json:"sizeInBytes,omitempty"`
80+
CreationTime time.Time `json:"datetime,omitempty"`
81+
}
82+
83+
type BackupRestoreResponse struct {
84+
Previous string `json:"previous,omitempty"`
85+
}
86+
87+
type BackupListOptions struct {
88+
// Set to receive info about specific single backup
89+
ID string `json:"id,omitempty"`
90+
}
91+
92+
type ListBackupsResponse struct {
93+
Server string `json:"server,omitempty"`
94+
Backups map[string]BackupMeta `json:"list,omitempty"`
95+
}
96+
97+
type BackupMeta struct {
98+
BackupResponse
99+
100+
Version string `json:"version,omitempty"`
101+
Available bool `json:"available,omitempty"`
102+
NumberOfPiecesPresent uint `json:"nrPiecesPresent,omitempty"`
103+
Keys []BackupMetaSha256 `json:"keys,omitempty"`
104+
}
105+
106+
type BackupMetaSha256 struct {
107+
SHA256 string `json:"sha256"`
108+
}
109+
110+
// BackupTransferStatus represents all possible states a transfer job can be in
111+
type BackupTransferStatus string
112+
113+
const (
114+
TransferAcknowledged BackupTransferStatus = "ACK"
115+
TransferStarted BackupTransferStatus = "STARTED"
116+
TransferCompleted BackupTransferStatus = "COMPLETED"
117+
TransferFailed BackupTransferStatus = "FAILED"
118+
TransferCancelled BackupTransferStatus = "CANCELLED"
119+
)
120+
121+
type BackupTransferProgressResponse struct {
122+
BackupID string `json:"BackupId,omitempty"`
123+
Cancelled bool `json:"Cancelled,omitempty"`
124+
Timestamp string `json:"Timestamp,omitempty"`
125+
DBServers map[string]BackupTransferReport `json:"DBServers,omitempty"`
126+
}
127+
128+
type BackupTransferReport struct {
129+
Status BackupTransferStatus `json:"Status,omitempty"`
130+
Error int `json:"Error,omitempty"`
131+
ErrorMessage string `json:"ErrorMessage,omitempty"`
132+
Progress struct {
133+
Total int `json:"Total,omitempty"`
134+
Done int `json:"Done,omitempty"`
135+
Timestamp string `json:"Timestamp,omitempty"`
136+
} `json:"Progress,omitempty"`
137+
}

0 commit comments

Comments
 (0)