add options to set backup destination and target container manager. Also fix typo in to write backups to correct location

This commit is contained in:
adam committed 2026-01-09 13:04:14 +00:00
1 parent 9773050cd3
commit 4caa5b05e1
1 file changed
+15 -8
+15 -8
View File
@@ -1,12 +1,19 @@
#!/usr/bin/env bash
main() {
while getopts ":l:" opt; do
while getopts ":l:d:t:" opt; do
case "${opt}" in
l)
unset VM_FILTER
IFS="," read -r -a VM_FILTER <<< "$OPTARG"
;;
d)
local backup_location="${OPTARG:-'.'}"
backup_location="${backup_location%/}"
;;
t)
declare -g TARGET="$OPTARG"
;;
*)
usage
;;
@@ -31,7 +38,7 @@ list_vms() {
lxc list -c n -f csv,noheader
}
usage() { echo "Usage: ${0##*/} [-l vm1,vm2,...]"; exit 1; }
usage() { echo "Usage: ${0##*/} [-l <vm[,vm...]>] [-d <backup_dir>] [-t <lxc|incus>]"; exit 1; }
backup_vms() {
local backup_location="$1"; shift
@@ -52,13 +59,13 @@ start_backup() {
local vm=$1
local backup_base="$2"
local destination="${backup_base}/${vm}"
echo "$vm -> $destination"
local backup_name="${vm}_$(date +"%Y-%m-%d_%H-%M-%S").tar.gz"
# Check destination base exists
# Check VM folder exists
# Check if archive already exists
echo "lxc export "$vm" "$destinationi/${vm}_$(date +"%Y-%m-%d_%H-%M-%S").tar.gz""
lxc export "$vm" "$destinationi/${vm}_$(date +"%Y-%m-%d_%H-%M-%S").tar.gz"
[[ -d "$backup_base" ]] || { echo "${backup_base} is not a directory"; exit 1; }
[[ -d "$destination" ]] || mkdir "$destination"
[[ -f "$destination/${backup_name}" ]] && { echo "Backup already exists"; return 2; }
lxc export "$vm" "$destination/${backup_name}"
}
main "$@"