]>
git.proxmox.com Git - proxmox-backup-qemu.git/blob - current-api.h
2 * A Proxmox Backup Server C interface, intended for use inside Qemu
4 * Copyright (C) 2019 Proxmox Server Solutions GmbH
7 * Dietmar Maurer (dietmar@proxmox.com)
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * NOTE: Async Commands
14 * Most commands are asynchronous (marked as _async). They run in a
15 * separate thread and have the following parameters:
17 * callback: extern "C" fn(*mut c_void),
18 * callback_data: *mut c_void,
20 * error: *mut *mut c_char,
22 * The callback function is called when the the async function is
23 * ready. Possible errors are returned in 'error'.
27 #ifndef PROXMOX_BACKUP_QEMU_H
28 #define PROXMOX_BACKUP_QEMU_H
35 #define PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE ((1024 * 1024) * 4)
38 * Opaque handle for backups jobs
40 typedef struct ProxmoxBackupHandle
{
42 } ProxmoxBackupHandle
;
45 * Opaque handle for restore jobs
47 typedef struct ProxmoxRestoreHandle
{
49 } ProxmoxRestoreHandle
;
52 * Return a read-only pointer to a string containing the version of the library.
54 const char *proxmox_backup_qemu_version(void);
57 * Free returned error messages
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.
63 void proxmox_backup_free_error(char *ptr
);
66 * Returns the text presentation (relative path) for a backup snapshot
68 * The resturned value is allocated with strdup(), and can be freed
71 const char *proxmox_backup_snapshot_string(const char *backup_type
,
72 const char *backup_id
,
77 * Create a new instance
79 * Uses `PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE` if `chunk_size` is zero.
81 struct ProxmoxBackupHandle
*proxmox_backup_new(const char *repo
,
82 const char *backup_id
,
87 const char *key_password
,
88 const char *master_keyfile
,
91 const char *fingerprint
,
95 * Open connection to the backup server (sync)
98 * 0 ... Sucecss (no prevbious backup)
99 * 1 ... Success (found previous backup)
102 int proxmox_backup_connect(struct ProxmoxBackupHandle
*handle
, char **error
);
105 * Open connection to the backup server
108 * 0 ... Sucecss (no prevbious backup)
109 * 1 ... Success (found previous backup)
112 void proxmox_backup_connect_async(struct ProxmoxBackupHandle
*handle
,
113 void (*callback
)(void*),
119 * Abort a running backup task
121 * This stops the current backup task. It is still necessary to call
122 * proxmox_backup_disconnect() to close the connection and free
125 void proxmox_backup_abort(struct ProxmoxBackupHandle
*handle
, const char *reason
);
128 * Check if we can do incremental backups.
130 * This method compares the csum from last backup manifest with the
131 * checksum stored locally.
133 int proxmox_backup_check_incremental(struct ProxmoxBackupHandle
*handle
,
134 const char *device_name
,
138 * Register a backup image (sync)
140 int proxmox_backup_register_image(struct ProxmoxBackupHandle
*handle
,
141 const char *device_name
,
147 * Register a backup image
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.
153 void proxmox_backup_register_image_async(struct ProxmoxBackupHandle
*handle
,
154 const char *device_name
,
157 void (*callback
)(void*),
163 * Add a configuration blob to the backup (sync)
165 int proxmox_backup_add_config(struct ProxmoxBackupHandle
*handle
,
172 * Add a configuration blob to the backup
174 * Create and upload a data blob "<name>.blob".
176 void proxmox_backup_add_config_async(struct ProxmoxBackupHandle
*handle
,
180 void (*callback
)(void*),
186 * Write data to into a registered image (sync)
188 * Upload a chunk of data for the <dev_id> image.
190 * The data pointer may be NULL in order to write the zero chunk
191 * (only allowed if size == chunk_size)
195 * 0: successful, chunk already exists on server, so it was resued
196 * size: successful, chunk uploaded
198 int proxmox_backup_write_data(struct ProxmoxBackupHandle
*handle
,
206 * Write data to into a registered image
208 * Upload a chunk of data for the <dev_id> image.
210 * The data pointer may be NULL in order to write the zero chunk
211 * (only allowed if size == chunk_size)
213 * Note: The data pointer needs to be valid until the async
214 * opteration is finished.
218 * 0: successful, chunk already exists on server, so it was resued
219 * size: successful, chunk uploaded
221 void proxmox_backup_write_data_async(struct ProxmoxBackupHandle
*handle
,
226 void (*callback
)(void*),
232 * Close a registered image (sync)
234 int proxmox_backup_close_image(struct ProxmoxBackupHandle
*handle
, uint8_t dev_id
, char **error
);
237 * Close a registered image
239 * Mark the image as closed. Further writes are not possible.
241 void proxmox_backup_close_image_async(struct ProxmoxBackupHandle
*handle
,
243 void (*callback
)(void*),
249 * Finish the backup (sync)
251 int proxmox_backup_finish(struct ProxmoxBackupHandle
*handle
, char **error
);
256 * Finish the backup by creating and uploading the backup manifest.
257 * All registered images have to be closed before calling this.
259 void proxmox_backup_finish_async(struct ProxmoxBackupHandle
*handle
,
260 void (*callback
)(void*),
266 * Disconnect and free allocated memory
268 * The handle becomes invalid after this call.
270 void proxmox_backup_disconnect(struct ProxmoxBackupHandle
*handle
);
273 * Connect the the backup server for restore (sync)
275 struct ProxmoxRestoreHandle
*proxmox_restore_new(const char *repo
,
276 const char *snapshot
,
277 const char *password
,
279 const char *key_password
,
280 const char *fingerprint
,
284 * Open connection to the backup server (sync)
287 * 0 ... Sucecss (no prevbious backup)
290 int proxmox_restore_connect(struct ProxmoxRestoreHandle
*handle
, char **error
);
293 * Open connection to the backup server (async)
296 * 0 ... Sucecss (no prevbious backup)
299 void proxmox_restore_connect_async(struct ProxmoxRestoreHandle
*handle
,
300 void (*callback
)(void*),
306 * Disconnect and free allocated memory
308 * The handle becomes invalid after this call.
310 void proxmox_restore_disconnect(struct ProxmoxRestoreHandle
*handle
);
313 * Restore an image (sync)
315 * Image data is downloaded and sequentially dumped to the callback.
317 int proxmox_restore_image(struct ProxmoxRestoreHandle
*handle
,
318 const char *archive_name
,
319 int (*callback
)(void*, uint64_t, const unsigned char*, uint64_t),
325 * Retrieve the ID of a handle used to access data in the given archive (sync)
327 int proxmox_restore_open_image(struct ProxmoxRestoreHandle
*handle
,
328 const char *archive_name
,
332 * Retrieve the ID of a handle used to access data in the given archive (async)
334 void proxmox_restore_open_image_async(struct ProxmoxRestoreHandle
*handle
,
335 const char *archive_name
,
336 void (*callback
)(void*),
342 * Retrieve the length of a given archive handle in bytes
344 long proxmox_restore_get_image_length(struct ProxmoxRestoreHandle
*handle
,
349 * Read data from the backup image at the given offset (sync)
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
355 * Note: It is not an error for a successful call to transfer fewer
356 * bytes than requested.
358 int proxmox_restore_read_image_at(struct ProxmoxRestoreHandle
*handle
,
366 * Read data from the backup image at the given offset (async)
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
372 * Note: The data pointer needs to be valid until the async
373 * opteration is finished.
375 * Note: The call will only ever transfer less than 'size' bytes if
376 * the end of the file has been reached.
378 void proxmox_restore_read_image_at_async(struct ProxmoxRestoreHandle
*handle
,
383 void (*callback
)(void*),
389 * Serialize all state data into a byte buffer. Can be loaded again with
390 * proxmox_import_state. Use for migration for example.
392 * Length of the returned buffer is written to buf_size. Returned buffer must
393 * be freed with proxmox_free_state_buf.
395 uint8_t *proxmox_export_state(uintptr_t *buf_size
);
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.
401 void proxmox_import_state(const uint8_t *buf
, uintptr_t buf_size
);
404 * Free a buffer acquired from proxmox_export_state.
406 void proxmox_free_state_buf(uint8_t *buf
);
408 #endif /* PROXMOX_BACKUP_QEMU_H */