basic process backup working
This commit is contained in:
1 parent
fbbc91780b
commit
9773050cd3
1 file changed
+49
-12
+49
-12
@@ -1,27 +1,64 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
lxc() {
|
|
||||||
_LXC="${TARGET:-lxc}"
|
|
||||||
command $_LXC "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
lxc_list() {
|
|
||||||
lxc list -c n -f csv,noheader "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
usage() { echo "Usage: ${0##*/} [-l vm1,vm2,...]"; exit 1; }
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
while getopts ":l:" opt; do
|
while getopts ":l:" opt; do
|
||||||
case "${opt}" in
|
case "${opt}" in
|
||||||
l)
|
l)
|
||||||
IFS="," read -r -a LIMIT <<< "$OPTARG"
|
unset VM_FILTER
|
||||||
|
IFS="," read -r -a VM_FILTER <<< "$OPTARG"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
local backup_location="/spool/backups"
|
||||||
|
|
||||||
|
if [[ "${#VM_FILTER[*]}" -gt 0 ]]; then
|
||||||
|
backup_vms "$backup_location" "${VM_FILTER[@]}"
|
||||||
|
else
|
||||||
|
backup_vms "$backup_location"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
lxc() {
|
||||||
|
local lxc_cmd="${TARGET:-lxc}"
|
||||||
|
command "$lxc_cmd" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
list_vms() {
|
||||||
|
lxc list -c n -f csv,noheader
|
||||||
|
}
|
||||||
|
|
||||||
|
usage() { echo "Usage: ${0##*/} [-l vm1,vm2,...]"; exit 1; }
|
||||||
|
|
||||||
|
backup_vms() {
|
||||||
|
local backup_location="$1"; shift
|
||||||
|
local vms=("$@")
|
||||||
|
|
||||||
|
# when no argument use list of all VMs
|
||||||
|
if ((${#vms[@]} == 0)); then
|
||||||
|
mapfile -t vms < <(list_vms)
|
||||||
|
fi
|
||||||
|
|
||||||
|
for vm in "${vms[@]}"; do
|
||||||
|
[[ -n $vm ]] || continue
|
||||||
|
start_backup "$vm" "$backup_location"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
start_backup() {
|
||||||
|
local vm=$1
|
||||||
|
local backup_base="$2"
|
||||||
|
local destination="${backup_base}/${vm}"
|
||||||
|
echo "$vm -> $destination"
|
||||||
|
|
||||||
|
# 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"
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
Reference in new issue
Block a user