diff --git a/scripts/backup.sh b/scripts/backup.sh index 4bfdca9..c07b78f 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -35,7 +35,7 @@ function backup_printer_cfg() { check_for_backup_dir local current_date - if [[ -f "${PRINTER_CFG}" ]]; then + if [[ -f ${PRINTER_CFG} ]]; then current_date=$(get_date) status_msg "Timestamp: ${current_date}" status_msg "Create backup of printer.cfg ..." @@ -70,7 +70,7 @@ function backup_moonraker_database() { 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 + if [[ -n ${databases} ]]; then current_date=$(get_date) target_dir="${BACKUP_DIR}/moonraker_database_backup/${current_date}" @@ -90,6 +90,36 @@ function backup_moonraker_database() { return } +### +# Helper function to back up all moonraker.conf files located in +# ${KLIPPER_CONFIG} and its subfolders +### +function backup_moonraker_conf() { + check_for_backup_dir + local current_date configs target_dir + configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort) + + if [[ -n ${configs} ]]; then + current_date=$(get_date) + target_dir="${BACKUP_DIR}/moonraker_conf_backup/${current_date}" + + status_msg "Timestamp: ${current_date}" + mkdir -p "${target_dir}" + + for config in ${configs}; do + status_msg "Create backup of ${config} ..." + cp -r "${config}" "${target_dir}" + ok_msg "Done!" + done + + print_confirm "Backup of all moonraker.conf complete!" + + else + print_error "No moonraker.conf found! Skipping backup ..." + fi + return +} + function backup_klipper() { local current_date