2023-09-07 16:06:51 -04:00
#!/usr/bin/env bash
2026-01-06 13:28:12 +01:00
# Copyright (c) 2021-2026 tteck
2023-09-07 16:06:51 -04:00
# Author: tteck (tteckster)
# License: MIT
2024-11-02 08:48:05 +01:00
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
2023-09-07 16:06:51 -04:00
function header_info {
2023-09-09 16:50:45 -04:00
clear
cat <<"EOF"
2023-09-07 16:06:51 -04:00
__ __ __ ___ __
/ // /__ ___ / /_ / _ ) ___ _____/ /____ _____
/ _ / _ \( _-</ __/ / _ / _ ` / __/ '_/ // / _ \
/_//_/\___/___/\__/ /____/\_,_/\__/_/\_\\_,_/ .__/
/_/
EOF
}
2026-02-17 16:36:20 +01:00
# Telemetry
2026-10-01 08:15:12 +02:00
source <(curl -fsSL "${COMMUNITY_SCRIPTS_CORE_URL:-https://raw.githubusercontent.com/community-scripts/core/main}/api/api.func") 2>/dev/null || true
2026-02-18 10:24:06 +01:00
declare -f init_tool_telemetry &>/dev/null && init_tool_telemetry "host-backup" "pve"
2026-02-17 16:36:20 +01:00
2023-09-09 20:50:26 -04:00
# Function to perform backup
function perform_backup {
local BACKUP_PATH
local DIR
local DIR_DASH
local BACKUP_FILE
local selected_directories=()
2023-09-07 16:06:51 -04:00
2023-09-09 20:50:26 -04:00
# Get backup path from user
BACKUP_PATH=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "\nDefaults to /root/\ne.g. /mnt/backups/" 11 68 --title "Directory to backup to:" 3>&1 1>&2 2>&3) || return
2023-09-07 16:06:51 -04:00
2023-09-09 20:50:26 -04:00
# Default to /root/ if no input
BACKUP_PATH="${BACKUP_PATH:-/root/}"
2023-09-09 16:50:45 -04:00
2023-09-09 20:50:26 -04:00
# Get directory to work in from user
DIR=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "\nDefaults to /etc/\ne.g. /root/, /var/lib/pve-cluster/ etc." 11 68 --title "Directory to work in:" 3>&1 1>&2 2>&3) || return
# Default to /etc/ if no input
DIR="${DIR:-/etc/}"
2023-09-09 16:50:45 -04:00
DIR_DASH=$(echo "$DIR" | tr ' /' ' -' )
2023-09-09 19:02:27 -04:00
BACKUP_FILE = " $( hostname) ${ DIR_DASH } backup"
2023-09-09 16:50:45 -04:00
2023-09-09 20:50:26 -04:00
# Build a list of directories for backup
local CTID_MENU =()
2025-10-11 17:20:06 +02:00
CTID_MENU =( "ALL" "Backup all folders" "OFF" )
2023-09-09 16:50:45 -04:00
while read -r dir; do
2023-09-09 20:50:26 -04:00
CTID_MENU +=( " $( basename " $dir " ) " " $dir " "OFF" )
done < <( ls -d " ${ DIR } " *)
2023-09-07 16:06:51 -04:00
2023-09-09 20:50:26 -04:00
# Allow the user to select directories
local HOST_BACKUP
2023-09-09 16:50:45 -04:00
while [ -z " ${ HOST_BACKUP :+x } " ] ; do
HOST_BACKUP = $( whiptail --backtitle "Proxmox VE Host Backup" --title "Working in the ${ DIR } directory " --checklist \
2023-09-09 20:50:26 -04:00
"\nSelect what files/directories to backup:\n" 16 $(( ( ${# DIRNAME } + 2 ) + 88 )) 6 " ${ CTID_MENU [@] } " 3>& 1 1>& 2 2>& 3) || return
2023-09-09 16:50:45 -04:00
for selected_dir in ${ HOST_BACKUP // \" / } ; do
2025-10-11 17:20:06 +02:00
if [[ " $selected_dir " == "ALL" ]] ; then
# if ALL was chosen, secure all folders
selected_directories =( " ${ DIR } " */)
break
else
selected_directories +=( " ${ DIR } $selected_dir " )
fi
2023-09-09 16:50:45 -04:00
done
2023-09-07 16:06:51 -04:00
done
2023-09-09 20:50:26 -04:00
# Perform the backup
2023-09-09 16:50:45 -04:00
header_info
2023-09-09 20:50:26 -04:00
echo -e "This will create a backup in\e[1;33m $BACKUP_PATH \e[0mfor these files and directories\e[1;33m ${ selected_directories [*] } \e[0m"
2023-09-09 16:50:45 -04:00
read -p "Press ENTER to continue..."
header_info
2023-09-09 17:07:58 -04:00
echo "Working..."
2025-10-11 17:20:06 +02:00
tar -czf " $BACKUP_PATH$BACKUP_FILE - $( date +%Y_%m_%dT%H_%M) .tar.gz" --absolute-names " ${ selected_directories [@] } "
2023-09-09 17:07:58 -04:00
header_info
2023-09-09 16:50:45 -04:00
echo -e "\nFinished"
2023-09-09 17:07:58 -04:00
echo -e "\e[1;33m \nA backup is rendered ineffective when it remains stored on the host.\n \e[0m"
2023-09-09 20:50:26 -04:00
sleep 2
2023-09-09 16:50:45 -04:00
}
2023-09-07 16:06:51 -04:00
2023-09-09 20:50:26 -04:00
# Main script execution loop
while true; do
if ( whiptail --backtitle "Proxmox VE Helper Scripts" --title "Proxmox VE Host Backup" --yesno "This will create backups for particular files and directories located within a designated directory. Proceed?" 10 88) ; then
perform_backup
else
break
fi
done