mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-02-04 23:10:16 +00:00
Fix: FS-Trim Cancel / Error-Button (#1965)
This commit is contained in:
parent
91ba5cd412
commit
e379db8baf
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
# Copyright (c) 2021-2025 tteck
|
# Copyright (c) 2021-2025 tteck
|
||||||
# Author: tteck (tteckster)
|
# Author: tteck (tteckster)
|
||||||
# License: MIT
|
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
||||||
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
function header_info() {
|
function header_info() {
|
||||||
clear
|
clear
|
||||||
@ -16,11 +17,13 @@ function header_info() {
|
|||||||
/____/
|
/____/
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
BL=$(echo "\033[36m")
|
BL=$(echo "\033[36m")
|
||||||
RD=$(echo "\033[01;31m")
|
RD=$(echo "\033[01;31m")
|
||||||
CM='\xE2\x9C\x94\033'
|
CM='\xE2\x9C\x94\033'
|
||||||
GN=$(echo "\033[1;92m")
|
GN=$(echo "\033[1;92m")
|
||||||
CL=$(echo "\033[m")
|
CL=$(echo "\033[m")
|
||||||
|
|
||||||
header_info
|
header_info
|
||||||
echo "Loading..."
|
echo "Loading..."
|
||||||
|
|
||||||
@ -29,50 +32,66 @@ if [ "$ROOT_FS" != "ext4" ]; then
|
|||||||
echo "Root filesystem is not ext4. Exiting script."
|
echo "Root filesystem is not ext4. Exiting script."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
whiptail --backtitle "Proxmox VE Helper Scripts" \
|
||||||
|
--title "Proxmox VE LXC Filesystem Trim" \
|
||||||
|
--yesno "The LXC containers will undergo the fstrim command. Proceed?" 10 58 || exit
|
||||||
|
|
||||||
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Proxmox VE LXC Filesystem Trim" --yesno "The LXC containers will undergo the fstrim command. Proceed?" 10 58 || exit
|
|
||||||
NODE=$(hostname)
|
NODE=$(hostname)
|
||||||
EXCLUDE_MENU=()
|
EXCLUDE_MENU=()
|
||||||
MSG_MAX_LENGTH=0
|
MSG_MAX_LENGTH=0
|
||||||
|
|
||||||
while read -r TAG ITEM; do
|
while read -r TAG ITEM; do
|
||||||
OFFSET=2
|
OFFSET=2
|
||||||
((${#ITEM} + OFFSET > MSG_MAX_LENGTH)) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
|
((${#ITEM} + OFFSET > MSG_MAX_LENGTH)) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
|
||||||
EXCLUDE_MENU+=("$TAG" "$ITEM " "OFF")
|
EXCLUDE_MENU+=("$TAG" "$ITEM " "OFF")
|
||||||
done < <(pct list | awk 'NR>1')
|
done < <(pct list | awk 'NR>1')
|
||||||
excluded_containers=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Containers on $NODE" --checklist "\nSelect containers to skip from trimming:\n" \
|
|
||||||
16 $((MSG_MAX_LENGTH + 23)) 6 "${EXCLUDE_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
|
excluded_containers_raw=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
|
||||||
|
--title "Containers on $NODE" \
|
||||||
|
--checklist "\nSelect containers to skip from trimming:\n" \
|
||||||
|
16 $((MSG_MAX_LENGTH + 23)) 6 "${EXCLUDE_MENU[@]}" 3>&1 1>&2 2>&3)
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
excluded_containers=$(echo "$excluded_containers_raw" | tr -d '"')
|
||||||
|
|
||||||
function trim_container() {
|
function trim_container() {
|
||||||
local container=$1
|
local container=$1
|
||||||
header_info
|
header_info
|
||||||
echo -e "${BL}[Info]${GN} Trimming ${BL}$container${CL} \n"
|
echo -e "${BL}[Info]${GN} Trimming ${BL}$container${CL} \n"
|
||||||
local before_trim=$(lvs | awk -F '[[:space:]]+' 'NR>1 && (/Data%|'"vm-$container"'/) {gsub(/%/, "", $7); print $7}')
|
|
||||||
|
local before_trim
|
||||||
|
before_trim=$(lvs | awk -F '[[:space:]]+' 'NR>1 && (/Data%|'"vm-$container"'/) {gsub(/%/, "", $7); print $7}')
|
||||||
echo -e "${RD}Data before trim $before_trim%${CL}"
|
echo -e "${RD}Data before trim $before_trim%${CL}"
|
||||||
pct fstrim $container
|
|
||||||
local after_trim=$(lvs | awk -F '[[:space:]]+' 'NR>1 && (/Data%|'"vm-$container"'/) {gsub(/%/, "", $7); print $7}')
|
pct fstrim "$container"
|
||||||
|
|
||||||
|
local after_trim
|
||||||
|
after_trim=$(lvs | awk -F '[[:space:]]+' 'NR>1 && (/Data%|'"vm-$container"'/) {gsub(/%/, "", $7); print $7}')
|
||||||
echo -e "${GN}Data after trim $after_trim%${CL}"
|
echo -e "${GN}Data after trim $after_trim%${CL}"
|
||||||
|
|
||||||
sleep 1.5
|
sleep 1.5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for container in $(pct list | awk '{if(NR>1) print $1}'); do
|
for container in $(pct list | awk '{if(NR>1) print $1}'); do
|
||||||
if [[ " ${excluded_containers[@]} " =~ " $container " ]]; then
|
if [[ " ${excluded_containers} " =~ " $container " ]]; then
|
||||||
header_info
|
header_info
|
||||||
echo -e "${BL}[Info]${GN} Skipping ${BL}$container${CL}"
|
echo -e "${BL}[Info]${GN} Skipping ${BL}$container${CL}"
|
||||||
sleep 1
|
sleep 1
|
||||||
else
|
else
|
||||||
template=$(pct config $container | grep -q "template:" && echo "true" || echo "false")
|
template=$(pct config "$container" | grep -q "template:" && echo "true" || echo "false")
|
||||||
if [ "$template" == "true" ]; then
|
if [ "$template" == "true" ]; then
|
||||||
header_info
|
header_info
|
||||||
echo -e "${BL}[Info]${GN} Skipping ${container} ${RD}$container is a template ${CL} \n"
|
echo -e "${BL}[Info]${GN} Skipping ${container} ${RD}$container is a template ${CL} \n"
|
||||||
sleep 1
|
sleep 1
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
trim_container $container
|
trim_container "$container"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
wait
|
wait
|
||||||
header_info
|
header_info
|
||||||
echo -e "${GN} Finished, LXC Containers Trimmed. ${CL} \n"
|
echo -e "${GN}Finished, LXC Containers Trimmed.${CL} \n"
|
||||||
|
Loading…
Reference in New Issue
Block a user