refactor(backups): update backup functions for config and moonraker database and enable backup-before-update again

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
th33xitus
2023-08-23 23:22:23 +02:00
parent 0497d49066
commit 9f410450d7
10 changed files with 42 additions and 42 deletions

View File

@@ -10,7 +10,6 @@
#=======================================================================# #=======================================================================#
# TODO: upload_log # TODO: upload_log
# TODO: all backup functions
# TODO: doublecheck that nothing got missed! # TODO: doublecheck that nothing got missed!
set -e set -e

View File

@@ -25,29 +25,32 @@ function check_for_backup_dir() {
} }
function backup_before_update() { function backup_before_update() {
echo "" read_kiauh_ini "${FUNCNAME[0]}"
### todo backup functions need to be updated for new folder structure local state="${backup_before_update}"
# read_kiauh_ini "${FUNCNAME[0]}" [[ ${state} = "false" ]] && return
# local state="${backup_before_update}" backup_"${1}"
# [[ ${state} = "false" ]] && return
# backup_"${1}"
} }
function backup_klipper_config_dir() { function backup_config_dir() {
check_for_backup_dir check_for_backup_dir
local current_date config_folder_name local current_date instance_names config_pathes
if [[ -d "${KLIPPER_CONFIG}" ]]; then config_pathes=$(get_config_folders)
readarray -t -d" " instance_names < <(get_multi_instance_names)
if [[ -n "${config_pathes}" ]]; then
current_date=$(get_date) current_date=$(get_date)
config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)"
status_msg "Timestamp: ${current_date}" status_msg "Timestamp: ${current_date}"
status_msg "Create backup of the Klipper config directory ..."
mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}" local i=0 folder
cp -r "${KLIPPER_CONFIG}" "${_}" for folder in ${config_pathes}; do
local folder_name="${instance_names[${i}]}"
print_confirm "Configuration directory backup complete!" status_msg "Create backup of ${folder} ..."
mkdir -p "${BACKUP_DIR}/configs/${current_date}/${folder_name}"
cp -r "${folder}" "${_}"
ok_msg "Backup created in:\n${BACKUP_DIR}/configs/${current_date}/${folder_name}"
i=$(( i + 1 ))
done
else else
ok_msg "No config directory found! Skipping backup ..." ok_msg "No config directory found! Skipping backup ..."
fi fi
@@ -55,27 +58,27 @@ function backup_klipper_config_dir() {
function backup_moonraker_database() { function backup_moonraker_database() {
check_for_backup_dir check_for_backup_dir
local current_date databases target_dir regex=".moonraker_database(_[0-9a-zA-Z]+)?" local current_date db_pathes
databases=$(find "${HOME}" -maxdepth 1 -type d -regextype posix-extended -regex "${HOME}/${regex}" | sort)
if [[ -n ${databases} ]]; then db_pathes=$(get_instance_folder_path "database")
readarray -t -d" " instance_names < <(get_multi_instance_names)
if [[ -n ${db_pathes} ]]; then
current_date=$(get_date) current_date=$(get_date)
target_dir="${BACKUP_DIR}/moonraker_database_backup/${current_date}"
status_msg "Timestamp: ${current_date}" status_msg "Timestamp: ${current_date}"
mkdir -p "${target_dir}"
for database in ${databases}; do local i=0 database
for database in ${db_pathes}; do
local folder_name="${instance_names[${i}]}"
status_msg "Create backup of ${database} ..." status_msg "Create backup of ${database} ..."
cp -r "${database}" "${target_dir}" mkdir -p "${BACKUP_DIR}/moonraker_databases/${current_date}/${folder_name}"
ok_msg "Done!" cp -r "${database}" "${_}"
ok_msg "Backup created in:\n${BACKUP_DIR}/moonraker_databases/${current_date}/${folder_name}"
i=$(( i + 1 ))
done done
print_confirm "Moonraker database backup complete!"
else else
print_error "No Moonraker database found! Skipping backup ..." print_error "No Moonraker database found! Skipping backup ..."
fi fi
return
} }
function backup_klipper() { function backup_klipper() {

View File

@@ -44,7 +44,7 @@ function install_fluidd() {
status_msg "Initializing Fluidd installation ..." status_msg "Initializing Fluidd installation ..."
### first, we create a backup of the full klipper_config dir - safety first! ### first, we create a backup of the full klipper_config dir - safety first!
#backup_klipper_config_dir backup_config_dir
### check for other enabled web interfaces ### check for other enabled web interfaces
unset SET_LISTEN_PORT unset SET_LISTEN_PORT

View File

@@ -103,7 +103,7 @@ function install_gcode_shell_command() {
function create_example_shell_command() { function create_example_shell_command() {
### create a backup of the config folder ### create a backup of the config folder
backup_klipper_config_dir backup_config_dir
local configs regex path local configs regex path
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg" regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg"
@@ -120,4 +120,4 @@ function create_example_shell_command() {
sed -i "1 i [include shell_command.cfg]" "${cfg}" sed -i "1 i [include shell_command.cfg]" "${cfg}"
fi fi
done done
} }

View File

@@ -30,7 +30,7 @@ function install_klipperscreen() {
fi fi
### first, we create a backup of the full klipper_config dir - safety first! ### first, we create a backup of the full klipper_config dir - safety first!
backup_klipper_config_dir backup_config_dir
### install KlipperScreen ### install KlipperScreen
klipperscreen_setup klipperscreen_setup

View File

@@ -44,7 +44,7 @@ function install_mainsail() {
status_msg "Initializing Mainsail installation ..." status_msg "Initializing Mainsail installation ..."
### first, we create a backup of the full klipper_config dir - safety first! ### first, we create a backup of the full klipper_config dir - safety first!
#backup_klipper_config_dir backup_config_dir
### check for other enabled web interfaces ### check for other enabled web interfaces
unset SET_LISTEN_PORT unset SET_LISTEN_PORT

View File

@@ -35,7 +35,7 @@ function install_mobileraker() {
fi fi
### first, we create a backup of the full klipper_config dir - safety first! ### first, we create a backup of the full klipper_config dir - safety first!
backup_klipper_config_dir backup_config_dir
### install Mobileraker's Companion ### install Mobileraker's Companion
mobileraker_setup mobileraker_setup

View File

@@ -33,7 +33,7 @@ function telegram_bot_setup_dialog() {
status_msg "Initializing Telegram Bot installation ..." status_msg "Initializing Telegram Bot installation ..."
### first, we create a backup of the full klipper_config dir - safety first! ### first, we create a backup of the full klipper_config dir - safety first!
backup_klipper_config_dir backup_config_dir
local moonraker_count user_input=() moonraker_names=() local moonraker_count user_input=() moonraker_names=()
moonraker_count=$(echo "${moonraker_services}" | wc -w ) moonraker_count=$(echo "${moonraker_services}" | wc -w )

View File

@@ -20,7 +20,7 @@ function backup_ui() {
echo -e "| Klipper & API: | Touchscreen GUI: |" echo -e "| Klipper & API: | Touchscreen GUI: |"
echo -e "| 1) [Klipper] | 7) [KlipperScreen] |" echo -e "| 1) [Klipper] | 7) [KlipperScreen] |"
echo -e "| 2) [Moonraker] | |" echo -e "| 2) [Moonraker] | |"
echo -e "| 3) [Configuration Folder] | 3rd Party Webinterface: |" echo -e "| 3) [Config Folder] | 3rd Party Webinterface: |"
echo -e "| 4) [Moonraker Database] | 8) [OctoPrint] |" echo -e "| 4) [Moonraker Database] | 8) [OctoPrint] |"
echo -e "| | |" echo -e "| | |"
echo -e "| Klipper Webinterface: | Other: |" echo -e "| Klipper Webinterface: | Other: |"
@@ -41,7 +41,7 @@ function backup_menu() {
2) 2)
do_action "backup_moonraker" "backup_ui";; do_action "backup_moonraker" "backup_ui";;
3) 3)
do_action "backup_klipper_config_dir" "backup_ui";; do_action "backup_config_dir" "backup_ui";;
4) 4)
do_action "backup_moonraker_database" "backup_ui";; do_action "backup_moonraker_database" "backup_ui";;
5) 5)

View File

@@ -21,8 +21,7 @@ function main_ui() {
echo -e "| 2) [Update] | Moonraker: $(print_status "moonraker")|" echo -e "| 2) [Update] | Moonraker: $(print_status "moonraker")|"
echo -e "| 3) [Remove] | |" echo -e "| 3) [Remove] | |"
echo -e "| 4) [Advanced] | Mainsail: $(print_status "mainsail")|" echo -e "| 4) [Advanced] | Mainsail: $(print_status "mainsail")|"
# echo -e "| 5) [Backup] | Fluidd: $(print_status "fluidd")|" echo -e "| 5) [Backup] | Fluidd: $(print_status "fluidd")|"
echo -e "| | Fluidd: $(print_status "fluidd")|"
echo -e "| | KlipperScreen: $(print_status "klipperscreen")|" echo -e "| | KlipperScreen: $(print_status "klipperscreen")|"
echo -e "| 6) [Settings] | Telegram Bot: $(print_status "telegram_bot")|" echo -e "| 6) [Settings] | Telegram Bot: $(print_status "telegram_bot")|"
echo -e "| | Crowsnest: $(print_status "crowsnest")|" echo -e "| | Crowsnest: $(print_status "crowsnest")|"
@@ -129,8 +128,7 @@ function main_menu() {
advanced_menu advanced_menu
break;; break;;
5)clear && print_header 5)clear && print_header
#backup_menu backup_menu
print_error "Function currently disabled! Sorry!"
main_ui;; main_ui;;
6)clear && print_header 6)clear && print_header
settings_menu settings_menu