|
| 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