From 9f410450d75d8b35ac4efa50e4d3aba14dfe8f1d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 23 Aug 2023 23:22:23 +0200 Subject: [PATCH] refactor(backups): update backup functions for config and moonraker database and enable backup-before-update again Signed-off-by: Dominik Willner --- kiauh.sh | 1 - scripts/backup.sh | 59 ++++++++++++++++--------------- scripts/fluidd.sh | 2 +- scripts/gcode_shell_command.sh | 4 +-- scripts/klipperscreen.sh | 2 +- scripts/mainsail.sh | 2 +- scripts/mobileraker.sh | 2 +- scripts/moonraker-telegram-bot.sh | 2 +- scripts/ui/backup_menu.sh | 4 +-- scripts/ui/main_menu.sh | 6 ++-- 10 files changed, 42 insertions(+), 42 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index c0fed70..57cee66 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -10,7 +10,6 @@ #=======================================================================# # TODO: upload_log -# TODO: all backup functions # TODO: doublecheck that nothing got missed! set -e diff --git a/scripts/backup.sh b/scripts/backup.sh index e918e22..bba5d32 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -25,29 +25,32 @@ function check_for_backup_dir() { } function backup_before_update() { - echo "" - ### todo backup functions need to be updated for new folder structure -# read_kiauh_ini "${FUNCNAME[0]}" -# local state="${backup_before_update}" -# [[ ${state} = "false" ]] && return -# backup_"${1}" + read_kiauh_ini "${FUNCNAME[0]}" + local state="${backup_before_update}" + [[ ${state} = "false" ]] && return + backup_"${1}" } -function backup_klipper_config_dir() { +function backup_config_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) - config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)" - status_msg "Timestamp: ${current_date}" - status_msg "Create backup of the Klipper config directory ..." - mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}" - cp -r "${KLIPPER_CONFIG}" "${_}" - - print_confirm "Configuration directory backup complete!" + local i=0 folder + for folder in ${config_pathes}; do + local folder_name="${instance_names[${i}]}" + 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 ok_msg "No config directory found! Skipping backup ..." fi @@ -55,27 +58,27 @@ function backup_klipper_config_dir() { function backup_moonraker_database() { check_for_backup_dir - local current_date databases target_dir regex=".moonraker_database(_[0-9a-zA-Z]+)?" - databases=$(find "${HOME}" -maxdepth 1 -type d -regextype posix-extended -regex "${HOME}/${regex}" | sort) + local current_date db_pathes - 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) - target_dir="${BACKUP_DIR}/moonraker_database_backup/${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} ..." - cp -r "${database}" "${target_dir}" - ok_msg "Done!" + mkdir -p "${BACKUP_DIR}/moonraker_databases/${current_date}/${folder_name}" + cp -r "${database}" "${_}" + ok_msg "Backup created in:\n${BACKUP_DIR}/moonraker_databases/${current_date}/${folder_name}" + i=$(( i + 1 )) done - - print_confirm "Moonraker database backup complete!" else print_error "No Moonraker database found! Skipping backup ..." fi - return } function backup_klipper() { diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 71d5819..4df3809 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -44,7 +44,7 @@ function install_fluidd() { status_msg "Initializing Fluidd installation ..." ### 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 unset SET_LISTEN_PORT diff --git a/scripts/gcode_shell_command.sh b/scripts/gcode_shell_command.sh index 48d52a2..1185642 100644 --- a/scripts/gcode_shell_command.sh +++ b/scripts/gcode_shell_command.sh @@ -103,7 +103,7 @@ function install_gcode_shell_command() { function create_example_shell_command() { ### create a backup of the config folder - backup_klipper_config_dir + backup_config_dir local configs regex path 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}" fi done -} \ No newline at end of file +} diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index 65ac223..dc90643 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -30,7 +30,7 @@ function install_klipperscreen() { fi ### first, we create a backup of the full klipper_config dir - safety first! - backup_klipper_config_dir + backup_config_dir ### install KlipperScreen klipperscreen_setup diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index c8c1b50..743170b 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -44,7 +44,7 @@ function install_mainsail() { status_msg "Initializing Mainsail installation ..." ### 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 unset SET_LISTEN_PORT diff --git a/scripts/mobileraker.sh b/scripts/mobileraker.sh index 45b8055..8520ec3 100644 --- a/scripts/mobileraker.sh +++ b/scripts/mobileraker.sh @@ -35,7 +35,7 @@ function install_mobileraker() { fi ### first, we create a backup of the full klipper_config dir - safety first! - backup_klipper_config_dir + backup_config_dir ### install Mobileraker's Companion mobileraker_setup diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index afccef8..41f0a22 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -33,7 +33,7 @@ function telegram_bot_setup_dialog() { status_msg "Initializing Telegram Bot installation ..." ### 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=() moonraker_count=$(echo "${moonraker_services}" | wc -w ) diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh index c908b44..c4f56c4 100755 --- a/scripts/ui/backup_menu.sh +++ b/scripts/ui/backup_menu.sh @@ -20,7 +20,7 @@ function backup_ui() { echo -e "| Klipper & API: | Touchscreen GUI: |" echo -e "| 1) [Klipper] | 7) [KlipperScreen] |" 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 "| | |" echo -e "| Klipper Webinterface: | Other: |" @@ -41,7 +41,7 @@ function backup_menu() { 2) do_action "backup_moonraker" "backup_ui";; 3) - do_action "backup_klipper_config_dir" "backup_ui";; + do_action "backup_config_dir" "backup_ui";; 4) do_action "backup_moonraker_database" "backup_ui";; 5) diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index f272684..b833d4f 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -21,8 +21,7 @@ function main_ui() { echo -e "| 2) [Update] | Moonraker: $(print_status "moonraker")|" echo -e "| 3) [Remove] | |" echo -e "| 4) [Advanced] | Mainsail: $(print_status "mainsail")|" -# echo -e "| 5) [Backup] | Fluidd: $(print_status "fluidd")|" - echo -e "| | Fluidd: $(print_status "fluidd")|" + echo -e "| 5) [Backup] | Fluidd: $(print_status "fluidd")|" echo -e "| | KlipperScreen: $(print_status "klipperscreen")|" echo -e "| 6) [Settings] | Telegram Bot: $(print_status "telegram_bot")|" echo -e "| | Crowsnest: $(print_status "crowsnest")|" @@ -129,8 +128,7 @@ function main_menu() { advanced_menu break;; 5)clear && print_header - #backup_menu - print_error "Function currently disabled! Sorry!" + backup_menu main_ui;; 6)clear && print_header settings_menu