mirror of https://github.com/tteck/Proxmox.git
Compare commits
6 Commits
6fae1fc557
...
e098af8ed9
Author | SHA1 | Date |
---|---|---|
|
e098af8ed9 | |
|
64b3958685 | |
|
4535f31d3d | |
|
8c4d2a3711 | |
|
06686f506a | |
|
b31de2b712 |
|
@ -4,6 +4,13 @@
|
|||
|
||||
- All LXC instances created using this repository come pre-installed with Midnight Commander, which is a command-line tool (`mc`) that offers a user-friendly file and directory management interface for the terminal environment.
|
||||
|
||||
## 2023-09-09
|
||||
|
||||
### Changed
|
||||
|
||||
- **Proxmox VE Host Backup**
|
||||
- Users are now able to specify both the backup path and the directory in which they wish to work.
|
||||
|
||||
## 2023-09-07
|
||||
|
||||
### Changed
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
# https://github.com/tteck/Proxmox/raw/main/LICENSE
|
||||
|
||||
function header_info {
|
||||
clear
|
||||
cat <<"EOF"
|
||||
clear
|
||||
cat <<"EOF"
|
||||
__ __ __ ___ __
|
||||
/ // /__ ___ / /_ / _ )___ _____/ /____ _____
|
||||
/ _ / _ \(_-</ __/ / _ / _ `/ __/ '_/ // / _ \
|
||||
|
@ -15,47 +15,65 @@ cat <<"EOF"
|
|||
/_/
|
||||
EOF
|
||||
}
|
||||
header_info
|
||||
while true; do
|
||||
read -p "This will backup specific files and directories within the 'etc' directory. Proceed (y/n)?" yn
|
||||
case $yn in
|
||||
[Yy]*) break ;;
|
||||
[Nn]*) exit ;;
|
||||
*) echo "Please answer yes or no." ;;
|
||||
esac
|
||||
done
|
||||
header_info
|
||||
|
||||
BACKUP_PATH="/root/"
|
||||
BACKUP_FILE="$(hostname)-host-backup"
|
||||
selected_directories=()
|
||||
# Function to perform backup
|
||||
function perform_backup {
|
||||
local BACKUP_PATH
|
||||
local DIR
|
||||
local DIR_DASH
|
||||
local BACKUP_FILE
|
||||
local 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")
|
||||
done < <(ls -d /etc/*)
|
||||
# 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
|
||||
|
||||
while [ -z "${HOST_BACKUP:+x}" ]; do
|
||||
HOST_BACKUP=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "SELECTIONS" --checklist \
|
||||
"\nSelect what files/directories to backup:\n" \
|
||||
16 $(($MSG_MAX_LENGTH + 58)) 6 \
|
||||
"${CTID_MENU[@]}" 3>&1 1>&2 2>&3) || exit
|
||||
# Default to /root/ if no input
|
||||
BACKUP_PATH="${BACKUP_PATH:-/root/}"
|
||||
|
||||
for selected_dir in ${HOST_BACKUP//\"}; do
|
||||
selected_directories+=("/etc/$selected_dir")
|
||||
# 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/}"
|
||||
|
||||
DIR_DASH=$(echo "$DIR" | tr '/' '-')
|
||||
BACKUP_FILE="$(hostname)${DIR_DASH}backup"
|
||||
|
||||
# Build a list of directories for backup
|
||||
local CTID_MENU=()
|
||||
while read -r dir; do
|
||||
CTID_MENU+=("$(basename "$dir")" "$dir " "OFF")
|
||||
done < <(ls -d "${DIR}"*)
|
||||
|
||||
# Allow the user to select directories
|
||||
local HOST_BACKUP
|
||||
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 $(((${#DIRNAME} + 2) + 88)) 6 "${CTID_MENU[@]}" 3>&1 1>&2 2>&3) || return
|
||||
|
||||
for selected_dir in ${HOST_BACKUP//\"/}; do
|
||||
selected_directories+=("${DIR}$selected_dir")
|
||||
done
|
||||
done
|
||||
|
||||
# Perform the backup
|
||||
header_info
|
||||
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"
|
||||
read -p "Press ENTER to continue..."
|
||||
header_info
|
||||
echo "Working..."
|
||||
tar -czf "$BACKUP_PATH$BACKUP_FILE-$(date +%Y_%m_%d).tar.gz" --absolute-names "${selected_directories[@]}"
|
||||
header_info
|
||||
echo -e "\nFinished"
|
||||
echo -e "\e[1;33m \nA backup is rendered ineffective when it remains stored on the host.\n \e[0m"
|
||||
sleep 2
|
||||
}
|
||||
|
||||
# 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
|
||||
|
||||
selected_directories_string=$(printf "%s " "${selected_directories[@]}")
|
||||
header_info
|
||||
echo -e "This will create backups for the directories \e[1;33m ${selected_directories_string% } \e[0m"
|
||||
read -p "Press ENTER to continue..."
|
||||
header_info
|
||||
tar -czf $BACKUP_PATH$BACKUP_FILE-$(date +%Y_%m_%d).tar.gz --absolute-names ${selected_directories_string% }
|
||||
|
||||
echo -e "\nFinished"
|
||||
echo -e "\e[1;33m \nA backup is rendered ineffective when it remains stored on the host.\n \e[0m"
|
||||
|
|
Loading…
Reference in New Issue