borgbackup/sync/
create.rs

1use log::{debug, info};
2
3use crate::common::{create_fmt_args, create_parse_output, CommonOptions, CreateOptions};
4use crate::errors::CreateError;
5use crate::output::create::Create;
6use crate::sync::execute_borg;
7
8/// This command creates a backup archive containing all files found
9/// while recursively traversing all paths specified.
10/// Paths are added to the archive as they are given,
11/// that means if relative paths are desired, the command has to be run from the correct directory.
12///
13/// **Parameter**:
14/// - `options`: Reference to [CreateOptions]
15/// - `common_options`: Reference to [CommonOptions]
16pub fn create(
17    options: &CreateOptions,
18    common_options: &CommonOptions,
19) -> Result<Create, CreateError> {
20    let local_path = common_options.local_path.as_ref().map_or("borg", |x| x);
21
22    let args = create_fmt_args(options, common_options, false);
23    debug!("Calling borg: {local_path} {args}");
24    let args = shlex::split(&args).ok_or(CreateError::ShlexError)?;
25    let res = execute_borg(local_path, args, &options.passphrase)?;
26
27    let stats = create_parse_output(res)?;
28
29    info!("Finished creating archive");
30
31    Ok(stats)
32}