Compare commits

..

1 Commits

Author SHA1 Message Date
MickLesk 9e320b5be8 feat(build): optional vzdump backup after install
Add advanced settings and host-side vzdump once the container is provisioned.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-19 22:49:18 +02:00
4 changed files with 100 additions and 227 deletions
-75
View File
@@ -1,75 +0,0 @@
#!/usr/bin/env bash
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
# Copyright (c) 2021-2026 community-scripts ORG
# Author: MickLesk (CanbiZ)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://github.com/apache/airflow
APP="Apache-Airflow"
var_tags="${var_tags:-workflow;scheduler;automation}"
var_cpu="${var_cpu:-2}"
var_ram="${var_ram:-4096}"
var_disk="${var_disk:-16}"
var_os="${var_os:-debian}"
var_version="${var_version:-13}"
var_arm64="${var_arm64:-no}"
var_unprivileged="${var_unprivileged:-1}"
header_info "$APP"
variables
color
catch_errors
function update_script() {
header_info
check_container_storage
check_container_resources
if [[ ! -d /opt/airflow ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
INSTALLED=$(cat ~/.airflow 2>/dev/null || echo "0")
LATEST=$(curl -fsSL "https://pypi.org/pypi/apache-airflow/json" | jq -r '.info.version')
if [[ "$INSTALLED" == "$LATEST" ]]; then
msg_ok "Already on the latest version (${LATEST})"
exit
fi
msg_info "Stopping Services"
systemctl stop airflow-api-server airflow-scheduler airflow-dag-processor airflow-triggerer
msg_ok "Stopped Services"
create_backup /opt/airflow/.env
msg_info "Updating Apache Airflow to ${LATEST}"
$STD uv pip install --python /opt/airflow/.venv/bin/python \
"apache-airflow[postgres,fab]==${LATEST}" \
--constraint "https://raw.githubusercontent.com/apache/airflow/constraints-${LATEST}/constraints-3.12.txt"
echo "${LATEST}" >~/.airflow
msg_ok "Updated Apache Airflow to ${LATEST}"
restore_backup
msg_info "Running Database Migrations"
set -a && source /opt/airflow/.env && set +a
$STD /opt/airflow/.venv/bin/airflow db migrate
msg_ok "Ran Database Migrations"
msg_info "Starting Services"
systemctl start airflow-api-server airflow-scheduler airflow-dag-processor airflow-triggerer
msg_ok "Started Services"
msg_ok "Updated successfully!"
exit
}
start
build_container
description
msg_ok "Completed Successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8080${CL}"
-6
View File
@@ -1,6 +0,0 @@
___ __ ___ _ ______
/ | ____ ____ ______/ /_ ___ / | (_)____/ __/ /___ _ __
/ /| | / __ \/ __ `/ ___/ __ \/ _ \______/ /| | / / ___/ /_/ / __ \ | /| / /
/ ___ |/ /_/ / /_/ / /__/ / / / __/_____/ ___ |/ / / / __/ / /_/ / |/ |/ /
/_/ |_/ .___/\__,_/\___/_/ /_/\___/ /_/ |_/_/_/ /_/ /_/\____/|__/|__/
/_/
-141
View File
@@ -1,141 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2026 community-scripts ORG
# Author: MickLesk (CanbiZ)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://github.com/apache/airflow
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os
msg_info "Installing Dependencies"
$STD apt install -y \
build-essential \
libpq-dev \
libssl-dev \
libffi-dev \
python3-dev
msg_ok "Installed Dependencies"
UV_PYTHON="3.12" setup_uv
PG_VERSION="16" setup_postgresql
PG_DB_NAME="airflow" PG_DB_USER="airflow" setup_postgresql_db
msg_info "Installing Apache Airflow"
AIRFLOW_VERSION="3.2.1"
mkdir -p /opt/airflow/{dags,logs,plugins}
cd /opt/airflow
$STD uv venv --python 3.12
$STD uv pip install --python /opt/airflow/.venv/bin/python \
"apache-airflow[postgres,fab]==${AIRFLOW_VERSION}" \
--constraint "https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-3.12.txt"
echo "${AIRFLOW_VERSION}" >~/.airflow
msg_ok "Installed Apache Airflow"
msg_info "Configuring Application"
FERNET_KEY=$(/opt/airflow/.venv/bin/python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())")
SECRET_KEY=$(openssl rand -hex 32)
ADMIN_PASS=$(openssl rand -base64 12 | tr -dc 'a-zA-Z0-9' | cut -c1-12)
cat <<EOF >/opt/airflow/.env
AIRFLOW_HOME=/opt/airflow
AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=postgresql+psycopg2://${PG_DB_USER}:${PG_DB_PASS}@localhost:5432/${PG_DB_NAME}
AIRFLOW__CORE__EXECUTOR=LocalExecutor
AIRFLOW__CORE__FERNET_KEY=${FERNET_KEY}
AIRFLOW__CORE__DAGS_FOLDER=/opt/airflow/dags
AIRFLOW__CORE__LOAD_EXAMPLES=false
AIRFLOW__CORE__AUTH_MANAGER=airflow.providers.fab.auth_manager.fab_auth_manager.FabAuthManager
AIRFLOW__API__AUTH_BACKENDS=airflow.api.auth.backend.basic_auth,airflow.api.auth.backend.session
AIRFLOW__WEBSERVER__SECRET_KEY=${SECRET_KEY}
AIRFLOW__WEBSERVER__BASE_URL=http://${LOCAL_IP}:8080
AIRFLOW_ADMIN_PASSWORD=${ADMIN_PASS}
EOF
set -a && source /opt/airflow/.env && set +a
$STD /opt/airflow/.venv/bin/airflow db migrate
$STD /opt/airflow/.venv/bin/airflow users create \
--username admin \
--firstname Admin \
--lastname User \
--role Admin \
--email admin@example.com \
--password "${ADMIN_PASS}"
msg_ok "Configured Application"
msg_info "Creating Services"
cat <<EOF >/etc/systemd/system/airflow-api-server.service
[Unit]
Description=Apache Airflow API Server
After=network.target postgresql.service
[Service]
Type=simple
User=root
EnvironmentFile=/opt/airflow/.env
ExecStart=/opt/airflow/.venv/bin/airflow api-server --port 8080
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF >/etc/systemd/system/airflow-scheduler.service
[Unit]
Description=Apache Airflow Scheduler
After=network.target postgresql.service
[Service]
Type=simple
User=root
EnvironmentFile=/opt/airflow/.env
ExecStart=/opt/airflow/.venv/bin/airflow scheduler
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF >/etc/systemd/system/airflow-dag-processor.service
[Unit]
Description=Apache Airflow DAG Processor
After=network.target postgresql.service
[Service]
Type=simple
User=root
EnvironmentFile=/opt/airflow/.env
ExecStart=/opt/airflow/.venv/bin/airflow dag-processor
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF >/etc/systemd/system/airflow-triggerer.service
[Unit]
Description=Apache Airflow Triggerer
After=network.target postgresql.service
[Service]
Type=simple
User=root
EnvironmentFile=/opt/airflow/.env
ExecStart=/opt/airflow/.venv/bin/airflow triggerer
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl enable -q --now airflow-api-server airflow-scheduler airflow-dag-processor airflow-triggerer
msg_ok "Created Services"
motd_ssh
customize
cleanup_lxc
+100 -5
View File
@@ -1075,7 +1075,7 @@ load_vars_file() {
var_gateway var_hostname var_ipv6_method var_mac var_mknod var_mount_fs var_mtu
var_net var_nesting var_ns var_os var_protection var_pw var_ram var_tags var_timezone var_tun var_unprivileged
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage var_searchdomain
var_post_install
var_post_install var_vzdump_after_install var_vzdump_storage
)
# Whitelist check helper
@@ -1250,6 +1250,20 @@ load_vars_file() {
continue
fi
;;
var_vzdump_after_install)
if [[ "$var_val" != "yes" && "$var_val" != "no" ]]; then
msg_warn "Invalid vzdump_after_install '$var_val' in $file (must be yes/no), ignoring"
continue
fi
;;
var_vzdump_storage)
local _vz_storage_status
_vz_storage_status=$(pvesm status 2>/dev/null | awk -v s="$var_val" '$1 == s { print $3 }')
if [[ -n "$var_val" && -z "$_vz_storage_status" ]]; then
msg_warn "Storage '$var_val' from $file not found on this node, ignoring"
continue
fi
;;
var_container_storage | var_template_storage)
# Validate that the storage exists and is active on the current node
local _storage_status
@@ -1293,7 +1307,7 @@ default_var_settings() {
var_gateway var_hostname var_ipv6_method var_mac var_mknod var_mount_fs var_mtu
var_net var_nesting var_ns var_os var_protection var_pw var_ram var_tags var_timezone var_tun var_unprivileged
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage
var_post_install
var_post_install var_vzdump_after_install var_vzdump_storage
)
# Snapshot: environment variables (highest precedence)
@@ -1394,6 +1408,10 @@ var_verbose=no
# Runs ON THE HOST after the container is fully provisioned.
# Available env vars: APP, NSAPP, CTID, IP, HN, STORAGE, BRG
# var_post_install=/opt/post-install/myhook.sh
# Optional vzdump backup after successful install (Proxmox host)
# var_vzdump_after_install=yes
# var_vzdump_storage=local
EOF
# Now choose storages (always prompt unless just one exists)
@@ -1472,7 +1490,7 @@ if ! declare -p VAR_WHITELIST >/dev/null 2>&1; then
var_gateway var_hostname var_ipv6_method var_mac var_mknod var_mount_fs var_mtu
var_net var_nesting var_ns var_os var_protection var_pw var_ram var_tags var_timezone var_tun var_unprivileged
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage var_searchdomain
var_post_install
var_post_install var_vzdump_after_install var_vzdump_storage
)
fi
@@ -1686,6 +1704,8 @@ _build_current_app_vars_tmp() {
[ -n "$_tpl_storage" ] && echo "var_template_storage=$(_sanitize_value "$_tpl_storage")"
[ -n "$_ct_storage" ] && echo "var_container_storage=$(_sanitize_value "$_ct_storage")"
[ -n "${var_post_install:-}" ] && echo "var_post_install=$(_sanitize_value "${var_post_install}")"
[ -n "${var_vzdump_after_install:-}" ] && echo "var_vzdump_after_install=$(_sanitize_value "${var_vzdump_after_install}")"
[ -n "${var_vzdump_storage:-}" ] && echo "var_vzdump_storage=$(_sanitize_value "${var_vzdump_storage}")"
} >"$tmpf"
echo "$tmpf"
@@ -1830,7 +1850,7 @@ advanced_settings() {
TAGS="community-script${var_tags:+;${var_tags}}"
fi
local STEP=1
local MAX_STEP=29
local MAX_STEP=30
# Store values for back navigation - inherit from var_* app defaults
local _ct_type="${var_unprivileged:-1}"
@@ -1865,6 +1885,8 @@ advanced_settings() {
local _mount_fs="${var_mount_fs:-}"
local _protect_ct="${var_protection:-no}"
local _post_install="${var_post_install:-}"
local _vzdump="${var_vzdump_after_install:-no}"
local _vzdump_storage="${var_vzdump_storage:-}"
# Detect host timezone for default (if not set via var_timezone)
local _host_timezone=""
@@ -2774,9 +2796,58 @@ Leave empty to skip."
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 29: Verbose Mode & Confirmation
# STEP 29: Optional vzdump backup after install
# ═══════════════════════════════════════════════════════════════════════════
29)
local vzdump_default_flag="--defaultno"
[[ "$_vzdump" == "yes" ]] && vzdump_default_flag=""
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "POST-INSTALL VZDUMP" \
--ok-button "Next" --cancel-button "Back" \
$vzdump_default_flag \
--yesno "\nCreate a vzdump backup after successful install?\n\nRuns on the Proxmox host once the container is ready.\n\n(App default: ${var_vzdump_after_install:-no})" 14 62; then
_vzdump="yes"
local _storages _menu_items=() _s
_storages=$(awk '
/^[a-z]+:/ { if (name != "") { if (has_backup || (!has_content && type == "dir")) print name }
split($0,a,":"); type=a[1]; name=a[2]; gsub(/^[ \t]+|[ \t]+$/, "", name); has_content=0; has_backup=0 }
/^[ \t]*content/ { has_content=1; if ($0 ~ /backup/) has_backup=1 }
END { if (name != "") { if (has_backup || (!has_content && type == "dir")) print name } }
' /etc/pve/storage.cfg 2>/dev/null)
if [[ -n "$_storages" ]]; then
while IFS= read -r _s; do
[[ -n "$_s" ]] && _menu_items+=("$_s" " ")
done <<<"$_storages"
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "VZDUMP STORAGE" \
--ok-button "Next" --cancel-button "Back" \
--menu "\nSelect backup storage:" 16 58 8 \
"${_menu_items[@]}" \
3>&1 1>&2 2>&3); then
_vzdump_storage="$result"
fi
else
whiptail --msgbox "No backup-capable storage found.\n\nConfigure storage with 'backup' content in Proxmox first." 10 58
_vzdump="no"
_vzdump_storage=""
fi
else
if [ $? -eq 1 ]; then
_vzdump="no"
_vzdump_storage=""
else
((STEP--))
continue
fi
fi
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 30: Verbose Mode & Confirmation
# ═══════════════════════════════════════════════════════════════════════════
30)
local verbose_default_flag="--defaultno"
[[ "$_verbose" == "yes" ]] && verbose_default_flag=""
@@ -2878,6 +2949,8 @@ Advanced:
APT_CACHER_IP="$_apt_cacher_ip"
VERBOSE="$_verbose"
var_post_install="$_post_install"
var_vzdump_after_install="$_vzdump"
var_vzdump_storage="$_vzdump_storage"
# Update var_* based on user choice (for functions that check these)
var_gpu="$_enable_gpu"
@@ -6585,6 +6658,26 @@ create_lxc_container() {
# SECTION 9: POST-INSTALLATION & FINALIZATION
# ==============================================================================
# ------------------------------------------------------------------------------
# _run_post_install_vzdump()
#
# - Optional vzdump on the Proxmox host after a successful install
# - Controlled by var_vzdump_after_install / var_vzdump_storage
# ------------------------------------------------------------------------------
_run_post_install_vzdump() {
[[ "${var_vzdump_after_install:-no}" != "yes" ]] && return 0
[[ -z "${CTID:-}" ]] && return 0
local storage="${var_vzdump_storage:-${CONTAINER_STORAGE:-local}}"
msg_info "Creating post-install vzdump backup (CT ${CTID}${storage})"
if vzdump "$CTID" --mode snapshot --compress zstd --storage "$storage" \
--notes-template "community-scripts post-install - ${APP:-LXC}" >>"${BUILD_LOG:-/dev/null}" 2>&1; then
msg_ok "Post-install vzdump created on ${storage}"
else
msg_warn "Post-install vzdump failed (storage: ${storage})"
fi
}
# ------------------------------------------------------------------------------
# description()
#
@@ -6683,6 +6776,8 @@ EOF
fi
fi
_run_post_install_vzdump
INSTALL_COMPLETE=true
post_update_to_api "done" "none"
}