]>
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 * DEPRECATED: Create a new instance in the root namespace.
79 * Uses `PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE` if `chunk_size` is zero.
81 * Deprecated in favor of `proxmox_backup_new_ns` which includes a namespace parameter.
83 struct ProxmoxBackupHandle
*proxmox_backup_new(const char *repo
,
84 const char *backup_id
,
89 const char *key_password
,
90 const char *master_keyfile
,
93 const char *fingerprint
,
97 * Create a new instance.
99 * `backup_ns` may be NULL and defaults to the root namespace.
101 * Uses `PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE` if `chunk_size` is zero.
103 struct ProxmoxBackupHandle
*proxmox_backup_new_ns(const char *repo
,
104 const char *backup_ns
,
105 const char *backup_id
,
106 uint64_t backup_time
,
108 const char *password
,
110 const char *key_password
,
111 const char *master_keyfile
,
114 const char *fingerprint
,
118 * Open connection to the backup server (sync)
121 * 0 ... Sucecss (no prevbious backup)
122 * 1 ... Success (found previous backup)
125 int proxmox_backup_connect(struct ProxmoxBackupHandle
*handle
, char **error
);
128 * Open connection to the backup server
131 * 0 ... Sucecss (no prevbious backup)
132 * 1 ... Success (found previous backup)
135 void proxmox_backup_connect_async(struct ProxmoxBackupHandle
*handle
,
136 void (*callback
)(void*),
142 * Abort a running backup task
144 * This stops the current backup task. It is still necessary to call
145 * proxmox_backup_disconnect() to close the connection and free
148 void proxmox_backup_abort(struct ProxmoxBackupHandle
*handle
, const char *reason
);
151 * Check if we can do incremental backups.
153 * This method compares the csum from last backup manifest with the
154 * checksum stored locally.
156 int proxmox_backup_check_incremental(struct ProxmoxBackupHandle
*handle
,
157 const char *device_name
,
161 * Register a backup image (sync)
163 int proxmox_backup_register_image(struct ProxmoxBackupHandle
*handle
,
164 const char *device_name
,
170 * Register a backup image
172 * Create a new image archive on the backup server
173 * ('<device_name>.img.fidx'). The returned integer is the dev_id
174 * parameter for the proxmox_backup_write_data_async() method.
176 void proxmox_backup_register_image_async(struct ProxmoxBackupHandle
*handle
,
177 const char *device_name
,
180 void (*callback
)(void*),
186 * Add a configuration blob to the backup (sync)
188 int proxmox_backup_add_config(struct ProxmoxBackupHandle
*handle
,
195 * Add a configuration blob to the backup
197 * Create and upload a data blob "<name>.blob".
199 void proxmox_backup_add_config_async(struct ProxmoxBackupHandle
*handle
,
203 void (*callback
)(void*),
209 * Write data to into a registered image (sync)
211 * Upload a chunk of data for the <dev_id> image.
213 * The data pointer may be NULL in order to write the zero chunk
214 * (only allowed if size == chunk_size)
218 * 0: successful, chunk already exists on server, so it was resued
219 * size: successful, chunk uploaded
221 int proxmox_backup_write_data(struct ProxmoxBackupHandle
*handle
,
229 * Write data to into a registered image
231 * Upload a chunk of data for the <dev_id> image.
233 * The data pointer may be NULL in order to write the zero chunk
234 * (only allowed if size == chunk_size)
236 * Note: The data pointer needs to be valid until the async
237 * opteration is finished.
241 * 0: successful, chunk already exists on server, so it was resued
242 * size: successful, chunk uploaded
244 void proxmox_backup_write_data_async(struct ProxmoxBackupHandle
*handle
,
249 void (*callback
)(void*),
255 * Close a registered image (sync)
257 int proxmox_backup_close_image(struct ProxmoxBackupHandle
*handle
, uint8_t dev_id
, char **error
);
260 * Close a registered image
262 * Mark the image as closed. Further writes are not possible.
264 void proxmox_backup_close_image_async(struct ProxmoxBackupHandle
*handle
,
266 void (*callback
)(void*),
272 * Finish the backup (sync)
274 int proxmox_backup_finish(struct ProxmoxBackupHandle
*handle
, char **error
);
279 * Finish the backup by creating and uploading the backup manifest.
280 * All registered images have to be closed before calling this.
282 void proxmox_backup_finish_async(struct ProxmoxBackupHandle
*handle
,
283 void (*callback
)(void*),
289 * Disconnect and free allocated memory
291 * The handle becomes invalid after this call.
293 void proxmox_backup_disconnect(struct ProxmoxBackupHandle
*handle
);
296 * DEPRECATED: Connect the the backup server for restore (sync)
298 * Deprecated in favor of `proxmox_restore_new_ns` which includes a namespace parameter.
299 * Also, it used "lossy" utf8 decoding on the snapshot name which is not the case in the new
302 struct ProxmoxRestoreHandle
*proxmox_restore_new(const char *repo
,
303 const char *snapshot
,
304 const char *password
,
306 const char *key_password
,
307 const char *fingerprint
,
311 * Connect the the backup server for restore (sync)
313 struct ProxmoxRestoreHandle
*proxmox_restore_new_ns(const char *repo
,
314 const char *snapshot
,
315 const char *namespace_
,
316 const char *password
,
318 const char *key_password
,
319 const char *fingerprint
,
323 * Open connection to the backup server (sync)
326 * 0 ... Sucecss (no prevbious backup)
329 int proxmox_restore_connect(struct ProxmoxRestoreHandle
*handle
, char **error
);
332 * Open connection to the backup server (async)
335 * 0 ... Sucecss (no prevbious backup)
338 void proxmox_restore_connect_async(struct ProxmoxRestoreHandle
*handle
,
339 void (*callback
)(void*),
345 * Disconnect and free allocated memory
347 * The handle becomes invalid after this call.
349 void proxmox_restore_disconnect(struct ProxmoxRestoreHandle
*handle
);
352 * Restore an image (sync)
354 * Image data is downloaded and sequentially dumped to the callback.
356 int proxmox_restore_image(struct ProxmoxRestoreHandle
*handle
,
357 const char *archive_name
,
358 int (*callback
)(void*, uint64_t, const unsigned char*, uint64_t),
364 * Retrieve the ID of a handle used to access data in the given archive (sync)
366 int proxmox_restore_open_image(struct ProxmoxRestoreHandle
*handle
,
367 const char *archive_name
,
371 * Retrieve the ID of a handle used to access data in the given archive (async)
373 void proxmox_restore_open_image_async(struct ProxmoxRestoreHandle
*handle
,
374 const char *archive_name
,
375 void (*callback
)(void*),
381 * Retrieve the length of a given archive handle in bytes
383 long proxmox_restore_get_image_length(struct ProxmoxRestoreHandle
*handle
,
388 * Read data from the backup image at the given offset (sync)
390 * Reads up to size bytes from handle aid at offset. On success,
391 * returns the number of bytes read. (a return of zero indicates end
394 * Note: It is not an error for a successful call to transfer fewer
395 * bytes than requested.
397 int proxmox_restore_read_image_at(struct ProxmoxRestoreHandle
*handle
,
405 * Read data from the backup image at the given offset (async)
407 * Reads up to size bytes from handle aid at offset. On success,
408 * returns the number of bytes read. (a return of zero indicates end
411 * Note: The data pointer needs to be valid until the async
412 * opteration is finished.
414 * Note: The call will only ever transfer less than 'size' bytes if
415 * the end of the file has been reached.
417 void proxmox_restore_read_image_at_async(struct ProxmoxRestoreHandle
*handle
,
422 void (*callback
)(void*),
428 * Serialize all state data into a byte buffer. Can be loaded again with
429 * proxmox_import_state. Use for migration for example.
431 * Length of the returned buffer is written to buf_size. Returned buffer must
432 * be freed with proxmox_free_state_buf.
434 uint8_t *proxmox_export_state(uintptr_t *buf_size
);
437 * Load state serialized by proxmox_export_state. If loading fails, a message
438 * will be logged to stderr, but the function will not fail.
440 void proxmox_import_state(const uint8_t *buf
, uintptr_t buf_size
);
443 * Free a buffer acquired from proxmox_export_state.
445 void proxmox_free_state_buf(uint8_t *buf
);
447 #endif /* PROXMOX_BACKUP_QEMU_H */