2023-11-13 09:33:28 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-03-18 10:26:05 -04:00
|
|
|
# SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
2023-11-13 09:33:28 -05:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2024-03-18 10:26:05 -04:00
|
|
|
list_backups(){
|
|
|
|
## Hide stderr to hide remote login connection messages (banners etc).
|
|
|
|
# shellcheck disable=SC2086
|
2024-07-09 11:42:07 -04:00
|
|
|
qvm-run --filter-escape-chars --no-color-output --no-color-stderr \
|
|
|
|
--pass-io "${qube}" -- "${cmd} ${find_cmd} 2>/dev/null"
|
2024-03-18 10:26:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
list_last_backup(){
|
|
|
|
list_backups | tail -1
|
|
|
|
}
|
|
|
|
|
2023-11-13 09:33:28 -05:00
|
|
|
usage(){
|
2024-03-18 10:26:05 -04:00
|
|
|
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"
|
2023-11-13 09:33:28 -05:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if test -z "${2-}"; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2024-03-18 10:26:05 -04:00
|
|
|
qube="${1}"
|
|
|
|
path="${2}"
|
2023-11-13 09:33:28 -05:00
|
|
|
cmd="${3-}"
|
|
|
|
|
2024-03-18 10:26:05 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
echo "${last_backup}"
|