qusal/salt/dom0/files/bin/qvm-backup-find-last
Ben Grande aea8438904
fix: stricter command-line parsing
- Add to qvm-run:
  - no-gui when command doesn't require a GUI
  - filter-escape-chars when pass-io is set and output is not a file,
    such as a pipe that could later be used to print information.
- Change remaining echo to printf
- Add end-of-options separator when possible
2025-01-08 16:12:31 +01:00

46 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# SPDX-FileCopyrightText: 2023 - 2025 Benjamin Grande M. S. <ben.grande.b@gmail.com>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
set -eu
list_backups(){
## Hide stderr to hide remote login connection messages (banners etc).
# shellcheck disable=SC2086
qvm-run --no-gui --filter-escape-chars --no-color-output --no-color-stderr \
--pass-io -- "${qube}" "${cmd} ${find_cmd} 2>/dev/null"
}
list_last_backup(){
list_backups | tail -1
}
usage(){
printf '%s\n' "Usage: ${0##*/} QUBE DIR [CMD]
example: ${0##*/} usb-qube /local/dir/backups
example: ${0##*/} ssh-qube /remote/dir/backups 'ssh user@server'
note: when using a remote login command (ssh), DIR is the remote directory
note: the directory specified must be the parent of the saved backups"
exit 1
}
if test -z "${2-}"; then
usage
fi
qube="${1}"
path="${2}"
cmd="${3-}"
find_pattern="qubes-backup-*"
find_cmd="find \"${path}\" -maxdepth 1 -type f -name \"${find_pattern}\""
last_backup="$(list_last_backup)"
if test -z "${last_backup}"; then
exit 1
fi
printf '%s\n' "${last_backup}"