proxmox backup client only one file

Evgenii36ru

New Member
Oct 25, 2021
20
0
1
44
Hello.
Can proxmox backup client backup files? there is a need to backup one large file. The file name changes every day. I did not find it in the documentation. Thank you
 
Not tested it but should be possible. Did you try to point the PBS client to a specific file instead of a folder?
If that is not working the PBS client got exclude filters which can be inverted so you can specify to only backup specific files matching a glob pattern.
 
Sorry for reopening an old thread. But apparently this doesn't work anymore in PBS 3.1, making me think that the feature has been intentionally disabled.

Code:
# proxmox-backup-client backup archive.pxar:/etc/hostname --repository 'backup@pbs!pbs-client-test@pbs-server.test.local:localrepo'
Error: got unexpected file type (expected directory)

whereas backing up the whole /etc directory with the above command works fine.
 
if you want to backup a single file, you need to do so as "image"/fixed-size index, not "host"/dynamic-sized index. in your example, instead of NAME.pxar:/etc/hostname you'd need to use NAME.img:/etc/hostname, or, for small files, NAME.conf:/etc/hostname (the last one is not chunked at all, but stored as-is in the snapshot dir as "blob", like the guest/firewall configs are in case of a PVE CT/VM backup).
 
I guess the last example there is confusing since it refers to block devices, but it's actually a "raw single file" mode that works for block devices, image files, or any other file you want to back up on its own :)
 
Almost 3 years later, this does not seem to be well documented.

Here are three suggestions that might steer people in the correct direction.

Suggestion 1 - Terminology page

https://pbs.proxmox.com/docs/terminology.html

Section names are:

Image Archives: <name>.img
[...]

File Archives: <name>.pxar
[...]

Binary Data (BLOBs)
[...]

Suggestion:

Image Archives: <name>.img
[...]

File Archives: <name>.pxar
[...]

Binary Data (BLOBs): <name>.conf / <name>.log
[...]


Suggestion 2 - Backup Client Usage page

https://pbs.proxmox.com/docs/backup-client.html#creating-backups

There is no mention of the .conf/.log types. There is only one mention of the .img type, which refers to block devices only.

The archive-name must contain alphanumerics, hyphens and underscores only. Common types are .pxar for file archives and .img for block device images. To create a backup of a block device, run the following command:

# proxmox-backup-client backup mydata.img:/dev/mylvm/mydata

Suggestion: mention that .img files may be used for regular files too. And also that .conf/.log files may be used for files < 16 MB (as per "Terminology" page).

Suggestion 3 - Command syntax page / Man page

No mention of the difference between formats. Suggestion:

Code:
proxmox-backup-client backup {<backupspec>} [OPTIONS]

Create (host) backup.

<backupspec>: string
  List of backup source specifications: [<archive-name>.<type>:<source-path>] ...

  The 'archive-name' must only contain alphanumerics, hyphens and
  underscores while the 'type' must be either 'pxar', 'img', 'conf'
  or 'log'. Can be specified more than once.
    pxar: Proxmox File Archive Format (stores a full directory tree)    ********
    img: image archive (VM images and other large binary data)          ********
    conf/log: smaller (< 16MB) binary data (eg: config and log files)   ********

The suggestion are the lines marked with `********` above.

Extra - Logic above in bash

This is how I implemented the logic above in my ansible bash jinja2 template. I pass only the paths, regardless of what they are (directory, small file, huge file), and it translates to the proper PBS type (pxar, img, conf, log).

Bash:
#!/bin/bash
set -Eeuo pipefail

set -a
source /etc/pbs-client/env
set +a

HOSTNAME_SHORT="$(hostname -s)"

PATHS=()
{% for path in pbs_backup_paths %}
PATHS+=( "{{ path }}" )
{% endfor %}

ARGS=()
for dest in "${PATHS[@]}"; do

    # The 'archive-name' must only contain alphanumerics, hyphens and
    # underscores.
    name=$(basename "$dest" | sed 's/[^A-Za-z0-9_-]/_/g')

    # Determination of data type. References:
    #   https://forum.proxmox.com/threads/proxmox-backup-client-only-one-file.104437/
    #   https://pbs.proxmox.com/docs/backup-client.html#creating-backups
    #   https://pbs.proxmox.com/docs/command-syntax.html#proxmox-backup-client
    #   https://pbs.proxmox.com/docs/terminology.html

    if ! [ -e "$dest" ]; then
        echo "Warning: $dest does not exist, skipping" >&2
        continue

    elif [ -d "$dest" ]; then
        # pxar: Proxmox File Archive Format (stores a full directory tree)
        type="pxar"

    elif [ -f "$dest" ]; then
        size=$(stat -c%s "$dest")
        if [ "$size" -lt $((16 * 1024 * 1024)) ]; then
            # conf/log: smaller (< 16MB) binary data (eg: config/log files)
            # we trim the suffix, if possible, to avoid *_conf.conf and *_log.log in the server
            if [[ $dest == *.log ]]; then
                if [[ $name != _log ]]; then
                    name=${name%_log}
                fi
                type="log"
            else
                if [[ $dest == *.conf && $name != _conf ]]; then
                    name=${name%_conf}
                fi
                type="conf"
            fi
        else
            # over 16MB, docs don't recommend blob
            type="img"
        fi
    elif [ -b "$dest" ]; then
        # img: image archive (VM images and other large binary data)
        type="img"
    else
        echo "Error: $dest is unknown path type" >&2
        exit 1
    fi

    ARGS+=("${name}.${type}:${dest}")
done

proxmox-backup-client backup \
    "${ARGS[@]}" \
    --backup-id "${HOSTNAME_SHORT}"
 
if you don't expect your small file to change often, using .img would still be beneficial - .conf/.log is never deduplicated but stored as-is. but yes, improving the docs here seems sensible!
 
if you don't expect your small file to change often, using .img would still be beneficial - .conf/.log is never deduplicated but stored as-is.
Hi @fabian, thanks for the reply. That right there is another very important piece of information that could be made explicit in the docs as well.