diff --git a/scripts/backup.sh b/scripts/backup.sh index 4288a54..bc1ea26 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -17,14 +17,14 @@ function get_date(){ } function check_for_backup_dir(){ - if [ ! -d "${BACKUP_DIR}" ]; then - status_msg "Create KIAUH backup directory ..." - mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!" - fi + [ -d "${BACKUP_DIR}" ] && return + status_msg "Create KIAUH backup directory ..." + mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!" } function backup_before_update(){ read_kiauh_ini + # shellcheck disable=SC2154 local state="${backup_before_update}" [ "${state}" = "false" ] && return backup_"${1}" @@ -52,7 +52,8 @@ function backup_klipper_config_dir(){ status_msg "Create backup of the Klipper config directory ..." config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)" mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}" - cp -r "${KLIPPER_CONFIG}" "${_}" && ok_msg "Backup complete!" + cp -r "${KLIPPER_CONFIG}" "${_}" + print_confirm "Configuration directory backup complete!" else ok_msg "No config directory found! Skipping backup ..." fi @@ -60,21 +61,24 @@ function backup_klipper_config_dir(){ function backup_moonraker_database(){ check_for_backup_dir - local current_date - if ls -d "${HOME}"/.moonraker_database* 2>/dev/null 1>&2; then + local current_date databases target_dir + + databases=$(find "${HOME}" -maxdepth 1 -type d -regextype posix-extended -regex "${HOME}/.moonraker_database(_[^0])?[0-9]*" | sort) + if [ -n "${databases}" ]; then current_date=$(get_date) + target_dir="${BACKUP_DIR}/moonraker_database_backup/${current_date}" status_msg "Timestamp: ${current_date}" - mkdir -p "${BACKUP_DIR}/mr_db_backup/${current_date}" - for database in $(ls -d ${HOME}/.moonraker_database*) - do + mkdir -p "${target_dir}" + for database in ${databases}; do status_msg "Create backup of ${database} ..." - cp -r "${database}" "${BACKUP_DIR}/mr_db_backup/${current_date}" + cp -r "${database}" "${target_dir}" ok_msg "Done!" done - ok_msg "Backup complete!\n" + print_confirm "Moonraker database backup complete!" else - ok_msg "No Moonraker database found! Skipping backup ..." + print_error "No Moonraker database found! Skipping backup ..." fi + return } function backup_klipper(){ @@ -85,7 +89,8 @@ function backup_klipper(){ current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/klipper-backups/${current_date}" - cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}" && ok_msg "Backup complete!" + cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}" + print_confirm "Klipper backup complete!" else print_error "Can't backup klipper and/or klipper-env directory! Not found!" fi @@ -99,7 +104,8 @@ function backup_mainsail(){ current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/mainsail-backups/${current_date}" - cp -r "${MAINSAIL_DIR}" "${_}" && ok_msg "Backup complete!" + cp -r "${MAINSAIL_DIR}" "${_}" + print_confirm "Mainsail backup complete!" else print_error "Can't backup mainsail directory! Not found!" fi @@ -113,7 +119,8 @@ function backup_fluidd(){ current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/fluidd-backups/${current_date}" - cp -r "${FLUIDD_DIR}" "${_}" && ok_msg "Backup complete!" + cp -r "${FLUIDD_DIR}" "${_}" + print_confirm "Fluidd backup complete!" else print_error "Can't backup fluidd directory! Not found!" fi @@ -127,7 +134,8 @@ function backup_moonraker(){ current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/moonraker-backups/${current_date}" - cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}" && ok_msg "Backup complete!" + cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}" + print_confirm "Moonraker backup complete!" else print_error "Can't backup moonraker and/or moonraker-env directory! Not found!" fi @@ -142,7 +150,7 @@ function backup_octoprint(){ status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/octoprint-backups/${current_date}" cp -r "${OCTOPRINT_DIR}" "${_}" && cp -r "${OCTOPRINT_CFG_DIR}" "${_}" - ok_msg "Backup complete!" + print_confirm " OctoPrint backup complete!" else print_error "Can't backup OctoPrint and/or .octoprint directory!\n Not found!" fi @@ -157,13 +165,13 @@ function backup_klipperscreen(){ status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/klipperscreen-backups/${current_date}" cp -r "${KLIPPERSCREEN_DIR}" "${_}" - ok_msg "Backup complete!" + print_confirm "KlipperScreen backup complete!" else print_error "Can't backup KlipperScreen directory!\n Not found!" fi } -function backup_MoonrakerTelegramBot(){ +function backup_telegram_bot(){ local current_date if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] ; then status_msg "Creating MoonrakerTelegramBot backup ..." @@ -172,7 +180,7 @@ function backup_MoonrakerTelegramBot(){ status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/MoonrakerTelegramBot-backups/${current_date}" cp -r "${MOONRAKER_TELEGRAM_BOT_DIR}" "${_}" - ok_msg "Backup complete!" + print_confirm "MoonrakerTelegramBot backup complete!" else print_error "Can't backup MoonrakerTelegramBot directory!\n Not found!" fi diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh index fef8bae..6e681c6 100755 --- a/scripts/ui/backup_menu.sh +++ b/scripts/ui/backup_menu.sh @@ -13,20 +13,19 @@ set -e function backup_ui(){ top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | " + echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") |" hr - echo -e "| ${yellow}Backup location: ~/kiauh-backups${white} | " + echo -e "| ${yellow}INFO: Backups are located in '~/kiauh-backups'${white} |" hr - echo -e "| Configuration folder: | Klipper Webinterface: | " - echo -e "| 0) [Klipper configs] | 4) [Mainsail] | " - echo -e "| | 5) [Fluidd] | " - echo -e "| Firmware: | | " - echo -e "| 1) [Klipper] | HDMI Screen: | " - echo -e "| | 6) [KlipperScreen] | " - echo -e "| Klipper API: | | " - echo -e "| 2) [Moonraker] | Other: | " - echo -e "| 3) [Moonraker DB] | 7) [OctoPrint] | " - echo -e "| | 8) [MoonrakerTelegramBot] | " + 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 "| 4) [Moonraker Database] | 8) [OctoPrint] |" + echo -e "| | |" + echo -e "| Klipper Webinterface: | Other: |" + echo -e "| 5) [Mainsail] | 9) [Telegram Bot] |" + echo -e "| 6) [Fluidd] | |" back_footer } @@ -35,24 +34,24 @@ function backup_menu(){ while true; do read -p "${cyan}####### Perform action:${white} " action case "${action}" in - 0) - do_action "backup_klipper_config_dir" "backup_ui";; 1) do_action "backup_klipper" "backup_ui";; 2) do_action "backup_moonraker" "backup_ui";; 3) - do_action "backup_moonraker_database" "backup_ui";; + do_action "backup_klipper_config_dir" "backup_ui";; 4) - do_action "backup_mainsail" "backup_ui";; + do_action "backup_moonraker_database" "backup_ui";; 5) - do_action "backup_fluidd" "backup_ui";; + do_action "backup_mainsail" "backup_ui";; 6) - do_action "backup_klipperscreen" "backup_ui";; + do_action "backup_fluidd" "backup_ui";; 7) - do_action "backup_octoprint" "backup_ui";; + do_action "backup_klipperscreen" "backup_ui";; 8) - do_action "backup_MoonrakerTelegramBot" "backup_ui";; + do_action "backup_octoprint" "backup_ui";; + 9) + do_action "backup_telegram_bot" "backup_ui";; B|b) clear; main_menu; break;; *)