backup menu

This commit is contained in:
paukstelis
2022-06-16 20:37:25 -04:00
parent 03a99c28db
commit 6a18a8c00d

View File

@@ -922,6 +922,22 @@ remove_everything() {
fi fi
fi fi
} }
create_menu() {
PS3='Select instance to backup: '
readarray -t options < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:alnum:]]*\) .*/\1/p')
options+=("Quit")
select opt in "${options[@]}"
do
if [ "$opt" == Quit ] || [ "$opt" == generic ]; then
main_menu
fi
echo "Selected instance to backup: $opt" | log
back_up $opt
done
main_menu
}
restart_all() { restart_all() {
get_settings get_settings
@@ -931,7 +947,7 @@ restart_all() {
continue continue
fi fi
echo "Trying to restart instance $instance" echo "Trying to restart instance $instance"
systemctl restart $instance systemctl restart $instance
done done
exit 0 exit 0
} }
@@ -940,10 +956,20 @@ back_up() {
INSTANCE=$1 INSTANCE=$1
echo "Creating backup of $INSTANCE...." echo "Creating backup of $INSTANCE...."
d=$(date '+%Y-%m-%d') d=$(date '+%Y-%m-%d')
sudo -p $user tar -czf ${INSTANCE}_${d}_backup.tar.gz /home/$user/.$INSTANCE sudo -p $user tar -czf ${INSTANCE}_${d}_backup.tar.gz -C /home/$user/ .${INSTANCE}
echo "Tarred and gzipped backup created in /home/$user" echo "Tarred and gzipped backup created in /home/$user"
} }
restore() {
INSTANCE=$1
TAR=$2
echo "Restoring backup of $INSTANCE...."
systemctl stop $INSTANCE
sudo -p $user tar -xvf $TAR
systemctl start $INSTANCE
}
back_up_all() { back_up_all() {
get_settings get_settings
readarray -t instances < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:alnum:]]*\) .*/\1/p') readarray -t instances < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:alnum:]]*\) .*/\1/p')
@@ -956,6 +982,7 @@ back_up_all() {
done done
} }
main_menu() { main_menu() {
#reset #reset
UDEV='' UDEV=''
@@ -966,7 +993,7 @@ main_menu() {
INSTALL='' INSTALL=''
PS3='Select operation: ' PS3='Select operation: '
if [ -f "/etc/octoprint_instances" ]; then if [ -f "/etc/octoprint_instances" ]; then
options=("New instance" "Delete instance" "Add Camera" "USB port testing" "Quit") options=("New instance" "Delete instance" "Add Camera" "USB port testing" "Create Backup" "Restore Backup" "Quit")
else else
options=("Prepare system" "USB port testing" "Quit") options=("Prepare system" "USB port testing" "Quit")
fi fi
@@ -993,6 +1020,14 @@ main_menu() {
usb_testing usb_testing
break break
;; ;;
"Create backup")
create_menu
break
;;
"Restore backup")
restore_menu
break
;;
"Quit") "Quit")
exit 1 exit 1
;; ;;