2023-09-07 22:06:51 +02:00
#!/usr/bin/env bash
# Copyright (c) 2021-2023 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE
function header_info {
2023-09-09 22:50:45 +02:00
clear
cat <<"EOF"
2023-09-07 22:06:51 +02:00
__ __ __ ___ __
/ // /__ ___ / /_ / _ ) ___ _____/ /____ _____
/ _ / _ \( _-</ __/ / _ / _ ` / __/ ' _/ // / _ \
/_//_/\_ __/___/\_ _/ /____/\_ ,_/\_ _/_/\_ \\ _,_/ .__/
/_/
EOF
}
header_info
2023-09-09 22:50:45 +02:00
start( ) {
2023-09-09 23:26:14 +02:00
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)
2023-09-07 22:06:51 +02:00
2023-09-09 22:50:45 +02:00
if [ -z " $BACKUP_PATH " ] ; then
BACKUP_PATH = "/root/"
else
BACKUP_PATH = " $BACKUP_PATH "
2023-09-07 22:06:51 +02:00
fi
2023-09-10 01:02:27 +02:00
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)
2023-09-09 22:50:45 +02:00
if [ -z " $DIR " ] ; then
2023-09-10 01:02:27 +02:00
DIR = "/etc/"
2023-09-09 22:50:45 +02:00
else
DIR = " $DIR "
fi
DIR_DASH = $( echo " $DIR " | tr '/' '-' )
2023-09-10 01:02:27 +02:00
BACKUP_FILE = " $( hostname) ${ DIR_DASH } backup "
2023-09-09 22:50:45 +02:00
selected_directories = ( )
while read -r dir; do
DIRNAME = $( basename " $dir " )
OFFSET = 2
if [ [ $(( ${# DIRNAME } + $OFFSET )) -gt ${ MSG_MAX_LENGTH :- } ] ] ; then
MSG_MAX_LENGTH = $(( ${# DIRNAME } + $OFFSET ))
fi
CTID_MENU += ( " $DIRNAME " " $dir " "OFF" )
2023-09-10 01:02:27 +02:00
done < <( ls -d ${ DIR } *)
2023-09-07 22:06:51 +02:00
2023-09-09 22:50:45 +02:00
while [ -z " ${ HOST_BACKUP : +x } " ] ; do
HOST_BACKUP = $( whiptail --backtitle "Proxmox VE Host Backup" --title " Working in the ${ DIR } directory " --checklist \
"\nSelect what files/directories to backup:\n" \
16 $(( $MSG_MAX_LENGTH + 58 )) 6 \
" ${ CTID_MENU [@] } " 3>& 1 1>& 2 2>& 3) || exit
for selected_dir in ${ HOST_BACKUP // \" / } ; do
2023-09-10 01:02:27 +02:00
selected_directories += ( " ${ DIR } ${ selected_dir } " )
2023-09-09 22:50:45 +02:00
done
2023-09-07 22:06:51 +02:00
done
2023-09-09 22:50:45 +02:00
selected_directories_string = $( printf "%s " " ${ selected_directories [@] } " )
header_info
2023-09-10 01:02:27 +02: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_string % } \e[0m "
2023-09-09 22:50:45 +02:00
read -p "Press ENTER to continue..."
header_info
2023-09-09 23:07:58 +02:00
echo "Working..."
2023-09-10 01:02:27 +02:00
tar -czf " ${ BACKUP_PATH } ${ BACKUP_FILE } - $( date +%Y_%m_%d) .tar.gz " --absolute-names ${ selected_directories_string % }
2023-09-09 23:07:58 +02:00
header_info
2023-09-09 22:50:45 +02:00
echo -e "\nFinished"
2023-09-09 23:07:58 +02:00
echo -e "\e[1;33m \nA backup is rendered ineffective when it remains stored on the host.\n \e[0m"
2023-09-09 22:50:45 +02:00
}
2023-09-07 22:06:51 +02:00
2023-09-09 22:50:45 +02:00
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
start
fi