diff --git a/kiauh.sh b/kiauh.sh index 33e781c..0727eab 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -69,7 +69,7 @@ title_msg(){ echo -e "${cyan}$1${default}" } get_date(){ - current_date=$(date +"%Y%m%d_%H%M") + current_date=$(date +"%y%m%d-%H%M") } print_unkown_cmd(){ ERROR_MSG="Invalid command!" diff --git a/scripts/backup.sh b/scripts/backup.sh index 9b27ecd..a27d62a 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -5,52 +5,6 @@ check_for_backup_dir(){ fi } -backup_printer_cfg(){ - check_for_backup_dir - if [ -f $PRINTER_CFG ]; then - get_date - status_msg "Create backup of printer.cfg ..." - cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup complete!" - else - ok_msg "No printer.cfg found! Skipping backup ..." - fi -} - -backup_klipper_config_dir(){ - source_kiauh_ini - check_for_backup_dir - if [ -d "$klipper_cfg_loc" ]; then - get_date - status_msg "Create backup of the Klipper config directory ..." - config_folder_name="$(echo "$klipper_cfg_loc" | rev | cut -d"/" -f1 | rev)" - cp -r "$klipper_cfg_loc" "$BACKUP_DIR/$config_folder_name.$current_date.backup" && ok_msg "Backup complete!" - echo - else - ok_msg "No config directory found! Skipping backup ..." - echo - fi -} - -backup_moonraker_conf(){ - check_for_backup_dir - if [ -f ${HOME}/moonraker.conf ]; then - get_date - status_msg "Create backup of moonraker.conf ..." - cp ${HOME}/moonraker.conf $BACKUP_DIR/moonraker.conf."$current_date".backup && ok_msg "Backup complete!" - else - ok_msg "No moonraker.conf found! Skipping backup ..." - fi -} - -read_bb4u_stat(){ - source_kiauh_ini - if [ ! "$backup_before_update" = "true" ]; then - BB4U_STATUS="${green}[Enable]${default} backups before updating " - else - BB4U_STATUS="${red}[Disable]${default} backups before updating " - fi -} - toggle_backups(){ source_kiauh_ini if [ "$backup_before_update" = "true" ]; then @@ -72,14 +26,70 @@ bb4u(){ fi } +read_bb4u_stat(){ + source_kiauh_ini + if [ ! "$backup_before_update" = "true" ]; then + BB4U_STATUS="${green}[Enable]${default} backups before updating " + else + BB4U_STATUS="${red}[Disable]${default} backups before updating " + fi +} + +############################################################################################## +#********************************************************************************************# +############################################################################################## + +backup_printer_cfg(){ + check_for_backup_dir + if [ -f $PRINTER_CFG ]; then + get_date + status_msg "Timestamp: $current_date" + status_msg "Create backup of printer.cfg ..." + cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup complete!" + else + ok_msg "No printer.cfg found! Skipping backup ..." + fi +} + +backup_klipper_config_dir(){ + source_kiauh_ini + check_for_backup_dir + if [ -d "$klipper_cfg_loc" ]; then + get_date + status_msg "Timestamp: $current_date" + status_msg "Create backup of the Klipper config directory ..." + config_folder_name="$(echo "$klipper_cfg_loc" | rev | cut -d"/" -f1 | rev)" + mkdir -p $BACKUP_DIR/$config_folder_name/$current_date + cp -r "$klipper_cfg_loc" "$_" && ok_msg "Backup complete!" + echo + else + ok_msg "No config directory found! Skipping backup ..." + echo + fi +} + + +###TODO re-evaluate if this function is still needed (just backup the full klipper_config dir instead?) +backup_moonraker_conf(){ + check_for_backup_dir + if [ -f ${HOME}/moonraker.conf ]; then + get_date + status_msg "Timestamp: $current_date" + status_msg "Create backup of moonraker.conf ..." + cp ${HOME}/moonraker.conf $BACKUP_DIR/moonraker.conf."$current_date".backup && ok_msg "Backup complete!" + else + ok_msg "No moonraker.conf found! Skipping backup ..." + fi +} + backup_klipper(){ - if [ -d $KLIPPER_DIR ] && [ -d $KLIPPY_ENV_DIR ]; then + if [ -d $KLIPPER_DIR ] && [ -d $KLIPPY_ENV ]; then status_msg "Creating Klipper backup ..." check_for_backup_dir get_date status_msg "Timestamp: $current_date" mkdir -p $BACKUP_DIR/klipper-backups/"$current_date" - cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV_DIR $_ && ok_msg "Backup complete!" + cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV $_ && ok_msg "Backup complete!" else ERROR_MSG=" Can't backup klipper and/or klipper-env directory! Not found!" fi