]> git.proxmox.com Git - proxmox-backup-qemu.git/blame - current-api.h
update dependencies to latest proxmox-backup git version
[proxmox-backup-qemu.git] / current-api.h
CommitLineData
b6e17373
WB
1/*
2 * A Proxmox Backup Server C interface, intended for use inside Qemu
3 *
4 * Copyright (C) 2019 Proxmox Server Solutions GmbH
5 *
6 * Authors:
7 * Dietmar Maurer (dietmar@proxmox.com)
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 *
11 *
12 * NOTE: Async Commands
13 *
14 * Most commands are asynchronous (marked as _async). They run in a
15 * separate thread and have the following parameters:
16 *
17 * callback: extern "C" fn(*mut c_void),
18 * callback_data: *mut c_void,
19 * result: *mut c_int,
20 * error: *mut *mut c_char,
21 *
22 * The callback function is called when the the async function is
23 * ready. Possible errors are returned in 'error'.
24 */
25
26
27#ifndef PROXMOX_BACKUP_QEMU_H
28#define PROXMOX_BACKUP_QEMU_H
29
30#include <stdarg.h>
31#include <stdbool.h>
32#include <stdint.h>
33#include <stdlib.h>
34
35#define PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE ((1024 * 1024) * 4)
36
37/**
38 * Opaque handle for backups jobs
39 */
2ddf3f7e 40typedef struct ProxmoxBackupHandle {
b6e17373
WB
41
42} ProxmoxBackupHandle;
43
44/**
45 * Opaque handle for restore jobs
46 */
2ddf3f7e 47typedef struct ProxmoxRestoreHandle {
b6e17373
WB
48
49} ProxmoxRestoreHandle;
50
51/**
2ddf3f7e 52 * Return a read-only pointer to a string containing the version of the library.
b6e17373 53 */
2ddf3f7e 54const char *proxmox_backup_qemu_version(void);
b6e17373
WB
55
56/**
2ddf3f7e 57 * Free returned error messages
b6e17373 58 *
2ddf3f7e
TL
59 * All calls can return error messages, but they are allocated using
60 * the rust standard library. This call moves ownership back to rust
61 * and free the allocated memory.
b6e17373 62 */
2ddf3f7e 63void proxmox_backup_free_error(char *ptr);
b6e17373 64
ca590e8f 65/**
2ddf3f7e 66 * Returns the text presentation (relative path) for a backup snapshot
ca590e8f 67 *
2ddf3f7e
TL
68 * The resturned value is allocated with strdup(), and can be freed
69 * with free().
b6e17373 70 */
2ddf3f7e
TL
71const char *proxmox_backup_snapshot_string(const char *backup_type,
72 const char *backup_id,
73 int64_t backup_time,
74 char **error);
b6e17373
WB
75
76/**
2ddf3f7e 77 * Create a new instance
b6e17373 78 *
2ddf3f7e 79 * Uses `PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE` if `chunk_size` is zero.
b6e17373 80 */
2ddf3f7e
TL
81struct ProxmoxBackupHandle *proxmox_backup_new(const char *repo,
82 const char *backup_id,
83 uint64_t backup_time,
84 uint64_t chunk_size,
85 const char *password,
86 const char *keyfile,
87 const char *key_password,
88 const char *master_keyfile,
89 bool compress,
90 bool encrypt,
91 const char *fingerprint,
92 char **error);
b6e17373
WB
93
94/**
95 * Open connection to the backup server (sync)
96 *
97 * Returns:
98 * 0 ... Sucecss (no prevbious backup)
99 * 1 ... Success (found previous backup)
100 * -1 ... Error
101 */
2ddf3f7e 102int proxmox_backup_connect(struct ProxmoxBackupHandle *handle, char **error);
b6e17373
WB
103
104/**
105 * Open connection to the backup server
106 *
107 * Returns:
108 * 0 ... Sucecss (no prevbious backup)
109 * 1 ... Success (found previous backup)
110 * -1 ... Error
111 */
2ddf3f7e 112void proxmox_backup_connect_async(struct ProxmoxBackupHandle *handle,
b6e17373
WB
113 void (*callback)(void*),
114 void *callback_data,
115 int *result,
116 char **error);
117
118/**
2ddf3f7e 119 * Abort a running backup task
b6e17373 120 *
2ddf3f7e
TL
121 * This stops the current backup task. It is still necessary to call
122 * proxmox_backup_disconnect() to close the connection and free
123 * allocated memory.
b6e17373 124 */
2ddf3f7e 125void proxmox_backup_abort(struct ProxmoxBackupHandle *handle, const char *reason);
b6e17373
WB
126
127/**
2ddf3f7e 128 * Check if we can do incremental backups.
b6e17373 129 *
2ddf3f7e
TL
130 * This method compares the csum from last backup manifest with the
131 * checksum stored locally.
f93eb142 132 */
2ddf3f7e
TL
133int proxmox_backup_check_incremental(struct ProxmoxBackupHandle *handle,
134 const char *device_name,
135 uint64_t size);
f93eb142 136
b6e17373
WB
137/**
138 * Register a backup image (sync)
139 */
2ddf3f7e 140int proxmox_backup_register_image(struct ProxmoxBackupHandle *handle,
b6e17373
WB
141 const char *device_name,
142 uint64_t size,
143 bool incremental,
144 char **error);
145
146/**
147 * Register a backup image
148 *
149 * Create a new image archive on the backup server
150 * ('<device_name>.img.fidx'). The returned integer is the dev_id
151 * parameter for the proxmox_backup_write_data_async() method.
b6e17373 152 */
2ddf3f7e 153void proxmox_backup_register_image_async(struct ProxmoxBackupHandle *handle,
b6e17373
WB
154 const char *device_name,
155 uint64_t size,
156 bool incremental,
157 void (*callback)(void*),
158 void *callback_data,
159 int *result,
160 char **error);
161
3be70641 162/**
2ddf3f7e
TL
163 * Add a configuration blob to the backup (sync)
164 */
165int proxmox_backup_add_config(struct ProxmoxBackupHandle *handle,
166 const char *name,
167 const uint8_t *data,
168 uint64_t size,
169 char **error);
170
171/**
172 * Add a configuration blob to the backup
3be70641 173 *
2ddf3f7e 174 * Create and upload a data blob "<name>.blob".
3be70641 175 */
2ddf3f7e
TL
176void proxmox_backup_add_config_async(struct ProxmoxBackupHandle *handle,
177 const char *name,
178 const uint8_t *data,
179 uint64_t size,
180 void (*callback)(void*),
181 void *callback_data,
182 int *result,
183 char **error);
3be70641 184
b6e17373
WB
185/**
186 * Write data to into a registered image (sync)
18a32972
DM
187 *
188 * Upload a chunk of data for the <dev_id> image.
189 *
3b024418
DM
190 * The data pointer may be NULL in order to write the zero chunk
191 * (only allowed if size == chunk_size)
192 *
193 * Returns:
194 * -1: on error
195 * 0: successful, chunk already exists on server, so it was resued
196 * size: successful, chunk uploaded
b6e17373 197 */
2ddf3f7e 198int proxmox_backup_write_data(struct ProxmoxBackupHandle *handle,
b6e17373
WB
199 uint8_t dev_id,
200 const uint8_t *data,
201 uint64_t offset,
202 uint64_t size,
203 char **error);
204
205/**
206 * Write data to into a registered image
207 *
208 * Upload a chunk of data for the <dev_id> image.
18a32972 209 *
26d37188
DM
210 * The data pointer may be NULL in order to write the zero chunk
211 * (only allowed if size == chunk_size)
212 *
213 * Note: The data pointer needs to be valid until the async
214 * opteration is finished.
3b024418
DM
215 *
216 * Returns:
217 * -1: on error
218 * 0: successful, chunk already exists on server, so it was resued
219 * size: successful, chunk uploaded
b6e17373 220 */
2ddf3f7e 221void proxmox_backup_write_data_async(struct ProxmoxBackupHandle *handle,
b6e17373
WB
222 uint8_t dev_id,
223 const uint8_t *data,
224 uint64_t offset,
225 uint64_t size,
226 void (*callback)(void*),
227 void *callback_data,
228 int *result,
229 char **error);
230
c28f578e 231/**
2ddf3f7e
TL
232 * Close a registered image (sync)
233 */
234int proxmox_backup_close_image(struct ProxmoxBackupHandle *handle, uint8_t dev_id, char **error);
235
236/**
237 * Close a registered image
c28f578e 238 *
2ddf3f7e 239 * Mark the image as closed. Further writes are not possible.
c28f578e 240 */
2ddf3f7e
TL
241void proxmox_backup_close_image_async(struct ProxmoxBackupHandle *handle,
242 uint8_t dev_id,
243 void (*callback)(void*),
244 void *callback_data,
245 int *result,
246 char **error);
c28f578e
SR
247
248/**
2ddf3f7e 249 * Finish the backup (sync)
c28f578e 250 */
2ddf3f7e 251int proxmox_backup_finish(struct ProxmoxBackupHandle *handle, char **error);
c28f578e
SR
252
253/**
2ddf3f7e
TL
254 * Finish the backup
255 *
256 * Finish the backup by creating and uploading the backup manifest.
257 * All registered images have to be closed before calling this.
c28f578e 258 */
2ddf3f7e
TL
259void proxmox_backup_finish_async(struct ProxmoxBackupHandle *handle,
260 void (*callback)(void*),
261 void *callback_data,
262 int *result,
263 char **error);
264
265/**
266 * Disconnect and free allocated memory
267 *
268 * The handle becomes invalid after this call.
269 */
270void proxmox_backup_disconnect(struct ProxmoxBackupHandle *handle);
271
272/**
273 * Connect the the backup server for restore (sync)
274 */
275struct ProxmoxRestoreHandle *proxmox_restore_new(const char *repo,
276 const char *snapshot,
277 const char *password,
278 const char *keyfile,
279 const char *key_password,
280 const char *fingerprint,
281 char **error);
c28f578e 282
b6e17373 283/**
932df897
DM
284 * Open connection to the backup server (sync)
285 *
286 * Returns:
287 * 0 ... Sucecss (no prevbious backup)
288 * -1 ... Error
289 */
2ddf3f7e 290int proxmox_restore_connect(struct ProxmoxRestoreHandle *handle, char **error);
932df897
DM
291
292/**
293 * Open connection to the backup server (async)
b6e17373 294 *
932df897
DM
295 * Returns:
296 * 0 ... Sucecss (no prevbious backup)
297 * -1 ... Error
b6e17373 298 */
2ddf3f7e 299void proxmox_restore_connect_async(struct ProxmoxRestoreHandle *handle,
932df897
DM
300 void (*callback)(void*),
301 void *callback_data,
302 int *result,
303 char **error);
b6e17373
WB
304
305/**
306 * Disconnect and free allocated memory
307 *
308 * The handle becomes invalid after this call.
309 */
2ddf3f7e 310void proxmox_restore_disconnect(struct ProxmoxRestoreHandle *handle);
932df897
DM
311
312/**
313 * Restore an image (sync)
b6e17373
WB
314 *
315 * Image data is downloaded and sequentially dumped to the callback.
316 */
2ddf3f7e 317int proxmox_restore_image(struct ProxmoxRestoreHandle *handle,
b6e17373
WB
318 const char *archive_name,
319 int (*callback)(void*, uint64_t, const unsigned char*, uint64_t),
320 void *callback_data,
321 char **error,
322 bool verbose);
323
932df897
DM
324/**
325 * Retrieve the ID of a handle used to access data in the given archive (sync)
326 */
2ddf3f7e 327int proxmox_restore_open_image(struct ProxmoxRestoreHandle *handle,
932df897
DM
328 const char *archive_name,
329 char **error);
330
331/**
332 * Retrieve the ID of a handle used to access data in the given archive (async)
333 */
2ddf3f7e 334void proxmox_restore_open_image_async(struct ProxmoxRestoreHandle *handle,
932df897
DM
335 const char *archive_name,
336 void (*callback)(void*),
337 void *callback_data,
338 int *result,
339 char **error);
340
2ddf3f7e
TL
341/**
342 * Retrieve the length of a given archive handle in bytes
343 */
344long proxmox_restore_get_image_length(struct ProxmoxRestoreHandle *handle,
345 uint8_t aid,
346 char **error);
347
932df897
DM
348/**
349 * Read data from the backup image at the given offset (sync)
350 *
351 * Reads up to size bytes from handle aid at offset. On success,
352 * returns the number of bytes read. (a return of zero indicates end
353 * of file).
354 *
355 * Note: It is not an error for a successful call to transfer fewer
356 * bytes than requested.
357 */
2ddf3f7e 358int proxmox_restore_read_image_at(struct ProxmoxRestoreHandle *handle,
932df897
DM
359 uint8_t aid,
360 uint8_t *data,
361 uint64_t offset,
362 uint64_t size,
363 char **error);
364
365/**
366 * Read data from the backup image at the given offset (async)
367 *
368 * Reads up to size bytes from handle aid at offset. On success,
369 * returns the number of bytes read. (a return of zero indicates end
370 * of file).
371 *
372 * Note: The data pointer needs to be valid until the async
373 * opteration is finished.
374 *
a9e0937c
SR
375 * Note: The call will only ever transfer less than 'size' bytes if
376 * the end of the file has been reached.
932df897 377 */
2ddf3f7e 378void proxmox_restore_read_image_at_async(struct ProxmoxRestoreHandle *handle,
932df897
DM
379 uint8_t aid,
380 uint8_t *data,
381 uint64_t offset,
382 uint64_t size,
383 void (*callback)(void*),
384 void *callback_data,
385 int *result,
386 char **error);
387
2ddf3f7e
TL
388/**
389 * Serialize all state data into a byte buffer. Can be loaded again with
390 * proxmox_import_state. Use for migration for example.
391 *
392 * Length of the returned buffer is written to buf_size. Returned buffer must
393 * be freed with proxmox_free_state_buf.
394 */
395uint8_t *proxmox_export_state(uintptr_t *buf_size);
396
397/**
398 * Load state serialized by proxmox_export_state. If loading fails, a message
399 * will be logged to stderr, but the function will not fail.
400 */
401void proxmox_import_state(const uint8_t *buf, uintptr_t buf_size);
402
403/**
404 * Free a buffer acquired from proxmox_export_state.
405 */
406void proxmox_free_state_buf(uint8_t *buf);
407
b6e17373 408#endif /* PROXMOX_BACKUP_QEMU_H */