diff --git a/usr/local/bin/lxc-update b/usr/local/bin/lxc-update new file mode 100644 index 0000000..78840ab --- /dev/null +++ b/usr/local/bin/lxc-update @@ -0,0 +1,43 @@ +#!/bin/bash +# +# Updates all running lxc containers on a proxmox host + +PATH="/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin" + +prog="$(basename "$0")" + +usage() { + cat >&2 <<-EOF + usage: $prog [-h] [-e EXCLUDELIST] + installs a preconfigured lxc container on your proxmox server + -e EXCLUDELIST list of container ids to exclude from backup (separator: |) + -h displays this help text + --------------------------------------------------------------------------- + (C) 2021 lxc-update by bashclub (https://github.com/bashclub) + --------------------------------------------------------------------------- + EOF + exit $1 +} + +condition="grep running" + +while getopts "hi:s:c:" opt; do + case $opt in + h) usage 0 ;; + e) condition="$condition | grep -vE '$OPTARG'" ;; + *) usage 1 ;; + esac +done +shift $((OPTIND-1)) + +ctlist=$(pct list | $condition | cut -d' ' -f1) + +for ct in $ctlist; do + for vol in $(pct config $ct | grep -E "^rootfs|^mp[0-9]+" | cut -d ' ' -f2 | cut -d',' -f1); do + snapvols="$snapvols $(pvesm path $vol | cut -d'/' -f2-)"; + done + zfs-auto-snapshot --quiet --syslog --label=lxc-auto-update --keep=2 --pre-snapshot=$(pct shutdown $ct && while [[ "$(pct status $ct)" == "status: running" ]];do sleep .1; echo "waiting for shutdown of ct $ct"; done) --post-snapshot=$(pct start $ct) $snapvols + pct exec $ct /usr/bin/apt update + pct exec $ct -- bash -c "DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical /usr/bin/apt -y -qq dist-upgrade" + snapvols= +done