From 1454b5417462439257a6569313f801826f40b128 Mon Sep 17 00:00:00 2001 From: Thorsten Spille Date: Sun, 27 Mar 2022 14:24:16 +0200 Subject: [PATCH] Create lxc-update --- usr/local/bin/lxc-update | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 usr/local/bin/lxc-update 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