From a540435e2176efca1d2f52ad0bb3d4010bb6d098 Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 13:13:43 +0100 Subject: [PATCH 01/17] Improve console output --- src/domposy.bash | 54 +++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/domposy.bash b/src/domposy.bash index fb2a2b7..981191c 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -93,6 +93,12 @@ declare -rx CONST_DEFAULT_LOG_DIR="/tmp/logs/" # ░░ ░░ # ░░░░░░░░░░░░░░░░░░░░░▓▓▓░░░░░░░░░░░░░░░░░░░░░░ +function abort { + echo "ERROR: $1" + echo "Aborting..." + exit 1 +} + function find_bin_script { local script_name="$1" local bin_paths=( @@ -132,18 +138,13 @@ function find_bin_script { declare -rx CONST_LOGGER_NAME="simbashlog" CONST_ORIGINAL_LOGGER_SCRIPT_PATH=$(find_bin_script "$CONST_LOGGER_NAME") || - { - echo "Critical: Unable to resolve logger script '$CONST_LOGGER_NAME'. Exiting..." - exit 1 - } + abort "Unable to resolve logger script '$CONST_LOGGER_NAME'" + declare -rx CONST_ORIGINAL_LOGGER_SCRIPT_PATH # shellcheck source=/dev/null source "$CONST_ORIGINAL_LOGGER_SCRIPT_PATH" >/dev/null 2>&1 || - { - echo "Critical: Unable to source logger script '$CONST_ORIGINAL_LOGGER_SCRIPT_PATH'. Exiting..." - exit 1 - } + abort "Unable to source logger script '$CONST_ORIGINAL_LOGGER_SCRIPT_PATH'" # shellcheck disable=SC2034 ENABLE_LOG_FILE=true @@ -187,7 +188,7 @@ function log_dry_run { log_notice "Dry run is enabled. Skipping '$1'" } -function log_delimiter { +function log_debug_delimiter { local level="$1" local text="$2" local char="$3" @@ -210,15 +211,15 @@ function log_delimiter { text=$(to_uppercase "$text") fi - log_info "$separator ${text} $separator" + log_debug "$separator ${text} $separator" } -function log_delimiter_start { - log_delimiter "$1" "$2" ">" false +function log_debug_delimiter_start { + log_debug_delimiter "$1" "$2" ">" false } -function log_delimiter_end { - log_delimiter "$1" "$2" "<" false +function log_debug_delimiter_end { + log_debug_delimiter "$1" "$2" "<" false } # ░░░░░░░░░░░░░░░░░░░░░▓▓▓░░░░░░░░░░░░░░░░░░░░░░ @@ -498,7 +499,7 @@ function _process_arguments { # Shows Docker information like disk usage, running containers, images etc. function show_docker_info { - log_delimiter_start 1 "DOCKER INFO" + log_debug_delimiter_start 1 "DOCKER INFO" log_info "docker system df..." log_notice "$(docker system df)" @@ -510,7 +511,7 @@ function show_docker_info { log_info "docker images..." log_notice "$(docker images)" - log_delimiter_end 1 "DOCKER INFO" + log_debug_delimiter_end 1 "DOCKER INFO" } # Returns the Docker Compose command. So whether 'docker-compose' or 'docker compose'. @@ -632,7 +633,7 @@ function _backup_single_docker_compose_project { file_simple_dirname=$(basename "$file_dir") log_debug_var "_backup_single_docker_compose_project" "file_simple_dirname" - log_delimiter_start 2 "'${file}'" + log_debug_delimiter_start 2 "'${file}'" cd "${file_dir}" || log_error "Failed to change directory to '${file_dir}'" log_notice "Changed directory to '$(pwd)'" @@ -657,11 +658,12 @@ function _backup_single_docker_compose_project { if $is_running; then _down; else log_notice "Skip 'down' because it is not running"; fi + log_info "Creating backup for '${file}'..." _create_backup_file_for_single_docker_compose_project "$backup_dir" "$file" if $is_running; then _up; else log_notice "Skip 'up' because it was not running"; fi - log_delimiter_end 2 "'${file}'" + log_debug_delimiter_end 2 "'${file}'" } function backup_docker_compose_projects { @@ -700,7 +702,7 @@ function backup_docker_compose_projects { if is_var_not_equal "$backup_dir" "$absolute_backup_dir"; then backup_dir="$absolute_backup_dir"; fi } - log_delimiter_start 1 "BACKUP" + log_debug_delimiter_start 1 "BACKUP" prepare_search_dir log_debug_var "backup_docker_compose_projects" "search_dir" @@ -725,7 +727,7 @@ function backup_docker_compose_projects { log_info "'${backup_dir}'..." if _is_dry_run_enabled; then log_dry_run "ls -larth $backup_dir"; else log_notice "$(ls -larth "$backup_dir")"; fi - log_delimiter_end 1 "BACKUP" + log_debug_delimiter_end 1 "BACKUP" } # ╔═════════════════════╦══════════════════════╗ @@ -737,7 +739,7 @@ function backup_docker_compose_projects { # Cleans the Docker environment by removing non-running containers, unused images and volumes. function clean_docker_environment { function _process_preview { - log_delimiter_start 2 "PREVIEW" + log_debug_delimiter_start 2 "PREVIEW" log_info "Listing non-running containers..." log_notice "$(docker ps -a --filter status=created --filter status=restarting --filter status=paused --filter status=exited --filter status=dead)" @@ -748,11 +750,11 @@ function clean_docker_environment { log_info "Listing unused volumes..." log_notice "$(docker volume ls --filter dangling=true)" - log_delimiter_end 2 "PREVIEW" + log_debug_delimiter_end 2 "PREVIEW" } function _process_remove { - log_delimiter_start 2 "REMOVE" + log_debug_delimiter_start 2 "REMOVE" log_notice "Removing non-running containers..." if _is_dry_run_enabled; then log_dry_run "docker container prune -f"; else log_notice "$(docker container prune -f)"; fi @@ -763,13 +765,13 @@ function clean_docker_environment { log_notice "Removing unused volumes..." if _is_dry_run_enabled; then log_dry_run "docker volume prune -f"; else log_notice "$(docker volume prune -f)"; fi - log_delimiter_end 2 "REMOVE" + log_debug_delimiter_end 2 "REMOVE" } - log_delimiter_start 1 "CLEAN" + log_debug_delimiter_start 1 "CLEAN" _process_preview _process_remove - log_delimiter_end 1 "CLEAN" + log_debug_delimiter_end 1 "CLEAN" } # ░░░░░░░░░░░░░░░░░░░░░▓▓▓░░░░░░░░░░░░░░░░░░░░░░ From a31bab1a772b08e101754eb7daeaa6d770de5145 Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 15:40:17 +0100 Subject: [PATCH 02/17] Implement logic to delete old backups, Closes #9 --- README.md | 3 ++ src/domposy.bash | 127 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 128 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4571da2..ac5e0d9 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,9 @@ Usage: (sudo) domposy Note: '-a, --action' should be used before this, otherwise it has no effect Default: '/tmp/domposy/backups/' + --keep-backups [keep backups] Number of backups to keep + Default: 'all' + --log-dir [log dir] Directory for log files Default: '/tmp/domposy/logs/' diff --git a/src/domposy.bash b/src/domposy.bash index 981191c..bec4a06 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -82,6 +82,7 @@ declare -rx CONST_DEFAULT_ACTION="backup" declare -rx CONST_DEFAULT_SEARCH_DIR="/home/" declare -rx CONST_DEFAULT_EXCLUDE_DIR="tmp" declare -rx CONST_DEFAULT_BACKUP_DIR="/tmp/${CONST_DOMPOSY_NAME}/backups/" +declare -rx CONST_DEFAULT_KEEP_BACKUPS="all" declare -rx CONST_DEFAULT_LOG_DIR="/tmp/logs/" @@ -294,6 +295,7 @@ declare -x _ARG_ACTION="${CONST_DEFAULT_ACTION}" declare -x _ARG_SEARCH_DIR="${CONST_DEFAULT_SEARCH_DIR}" declare -x _ARG_EXCLUDE_DIR="${CONST_DEFAULT_EXCLUDE_DIR}" declare -x _ARG_BACKUP_DIR="${CONST_DEFAULT_BACKUP_DIR}" +declare -x _ARG_KEEP_BACKUPS="${CONST_DEFAULT_KEEP_BACKUPS}" function _process_arguments { local arg_which_is_processed="" @@ -363,6 +365,9 @@ function _process_arguments { echo " $note_for_valid_action_for_backup" echo " Default: '$CONST_DEFAULT_BACKUP_DIR'" echo + echo " --keep-backups [keep backups] Number of backups to keep" + echo " Default: '$CONST_DEFAULT_KEEP_BACKUPS'" + echo echo " --log-dir [log dir] Directory for log files" echo " Default: '$CONST_DEFAULT_LOG_DIR'" echo @@ -456,6 +461,16 @@ function _process_arguments { _ARG_BACKUP_DIR="$1" log_debug_var "_process_arguments" "_ARG_BACKUP_DIR" ;; + --keep-backups) + log_debug "'$1' selected" + arg_which_is_processed="$1" + shift + _validate_if_value_is_argument "$1" + _log_error_if_value_is_empty "$1" + + _ARG_KEEP_BACKUPS="$1" + log_debug_var "_process_arguments" "_ARG_KEEP_BACKUPS" + ;; --log-dir) log_debug "'$1' selected" arg_which_is_processed="$1" @@ -635,6 +650,17 @@ function _backup_single_docker_compose_project { log_debug_delimiter_start 2 "'${file}'" + backup_dir="${backup_dir}${file_simple_dirname}/" + + if directory_not_exists "$backup_dir"; then + if _is_dry_run_enabled; then + log_dry_run "mkdir -p $backup_dir" + else + mkdir -p "$backup_dir" || log_error "Backup directory '$backup_dir' for file '$file' could not be created" + log_notice "Backup directory '$backup_dir' for file '$file' was created" + fi + fi + cd "${file_dir}" || log_error "Failed to change directory to '${file_dir}'" log_notice "Changed directory to '$(pwd)'" @@ -685,8 +711,6 @@ function backup_docker_compose_projects { function prepare_backup_dir { if ! contains_trailing_slash "$backup_dir"; then backup_dir="${backup_dir}/"; fi - backup_dir="${backup_dir}$(date +"%Y-%m-%d")/" - if directory_not_exists "$backup_dir"; then if _is_dry_run_enabled; then log_dry_run "mkdir -p $backup_dir" @@ -774,6 +798,102 @@ function clean_docker_environment { log_debug_delimiter_end 1 "CLEAN" } +# ╔═════════════════════╦══════════════════════╗ +# ║ ║ +# ║ DELETE OLD BACKUPS ║ +# ║ ║ +# ╚═════════════════════╩══════════════════════╝ + +function _delete_old_files { + local dir="$1" + local keep_files="$2" + + log_debug_var "_delete_old_files" "dir" + log_debug_var "_delete_old_files" "keep_files" + + if directory_exists "$dir"; then + log_info "Processing directory '$dir' for deletion of old files (keep: $keep_files)..." + + # Get all files sorted by date + mapfile -t files < <(ls -dt "$dir"/*) + + if is_var_empty "${files[*]}"; then + log_warn "No files found in '$dir'. Skipping deletion of old files." + return 1 + fi + + local number_of_files="${#files[@]}" + + log_debug "Files in '$dir' (number: $number_of_files):" + for file in "${files[@]}"; do + log_debug "$file" + done + + if ((${#files[@]} > keep_files)); then + local files_to_delete=("${files[@]:keep_files}") + + log_info "Old files to delete (${#files_to_delete[@]} / $number_of_files):" + for file_to_delete in "${files_to_delete[@]}"; do + log_info "$file_to_delete" + done + + for file_to_delete in "${files_to_delete[@]}"; do + log_info "Deleting old file '$file_to_delete'..." + + if _is_dry_run_enabled; then + log_dry_run "rm -rf $file_to_delete" + else + rm -rf "$file_to_delete" || log_error "Failed to delete file: '$file_to_delete'" + fi + + log_notice "Old file deleted: '$file_to_delete'" + done + fi + else + log_notice "Directory '$dir' does not exist. Skipping deletion of old files." + fi +} + +function delete_old_backups { + local backup_dir="$1" + local keep_backups="$2" + + log_debug_var "delete_old_backups" "backup_dir" + log_debug_var "delete_old_backups" "keep_backups" + + log_debug_delimiter_start 1 "DELETE OLD BACKUPS" + + if directory_not_exists "$backup_dir"; then + log_warn "Backup directory '$backup_dir' does not exist. Skipping deletion of old backups." + return 1 + fi + + if is_var_equal "$keep_backups" "all"; then + log_notice "All backups are kept. No backups will be deleted." + return 0 + fi + + if is_not_numeric "$keep_backups"; then + log_warn "Keep backups is not a number. Skipping deletion of old backups." + return 1 + fi + + if is_less "$keep_backups" 1; then + log_warn "It is not possible to keep less than 1 backup. You have to delete the backups manually." + return 1 + fi + + for sub_dir in "$backup_dir"/*; do + _delete_old_files "$sub_dir" "$keep_backups" || + { + log_warn "Deletion of old backups in '$sub_dir' failed" + return 1 + } + done + + log_debug_delimiter_end 1 "DELETE OLD BACKUPS" +} + # ░░░░░░░░░░░░░░░░░░░░░▓▓▓░░░░░░░░░░░░░░░░░░░░░░ # ░░ ░░ # ░░ ░░ @@ -802,6 +922,9 @@ clean) ;; esac +delete_old_backups "$_ARG_BACKUP_DIR" "$_ARG_KEEP_BACKUPS" || + log_warn "Deletion of old backups failed" + show_docker_info exit 0 From bea27aa4499688227dc3d3c4d9c2993f8139b76a Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 15:51:50 +0100 Subject: [PATCH 03/17] Fix double slash while deleting old files --- src/domposy.bash | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/domposy.bash b/src/domposy.bash index bec4a06..830fddd 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -811,11 +811,13 @@ function _delete_old_files { log_debug_var "_delete_old_files" "dir" log_debug_var "_delete_old_files" "keep_files" + if ! contains_trailing_slash "$dir"; then dir="${dir}/"; fi + if directory_exists "$dir"; then log_info "Processing directory '$dir' for deletion of old files (keep: $keep_files)..." # Get all files sorted by date - mapfile -t files < <(ls -dt "$dir"/*) + mapfile -t files < <(ls -dt "$dir"*) if is_var_empty "${files[*]}"; then log_warn "No files found in '$dir'. Skipping deletion of old files." @@ -861,8 +863,6 @@ function delete_old_backups { log_debug_var "delete_old_backups" "backup_dir" log_debug_var "delete_old_backups" "keep_backups" - log_debug_delimiter_start 1 "DELETE OLD BACKUPS" - if directory_not_exists "$backup_dir"; then log_warn "Backup directory '$backup_dir' does not exist. Skipping deletion of old backups." return 1 @@ -890,8 +890,6 @@ function delete_old_backups { return 1 } done - - log_debug_delimiter_end 1 "DELETE OLD BACKUPS" } # ░░░░░░░░░░░░░░░░░░░░░▓▓▓░░░░░░░░░░░░░░░░░░░░░░ @@ -922,8 +920,10 @@ clean) ;; esac +log_debug_delimiter_start 1 "DELETE OLD BACKUPS" delete_old_backups "$_ARG_BACKUP_DIR" "$_ARG_KEEP_BACKUPS" || log_warn "Deletion of old backups failed" +log_debug_delimiter_end 1 "DELETE OLD BACKUPS" show_docker_info From 3c32116c005e4f2169802b996dca7f030ccbfcf4 Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 16:19:40 +0100 Subject: [PATCH 04/17] Fix no subdirectories in backup dir when deleting old backup files --- src/domposy.bash | 77 ++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/src/domposy.bash b/src/domposy.bash index 830fddd..443aee5 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -748,7 +748,7 @@ function backup_docker_compose_projects { _backup_single_docker_compose_project "$backup_dir" "$file" done <<<"$docker_compose_files" - log_info "'${backup_dir}'..." + log_info "Backup directory content ('${backup_dir}'):" if _is_dry_run_enabled; then log_dry_run "ls -larth $backup_dir"; else log_notice "$(ls -larth "$backup_dir")"; fi log_debug_delimiter_end 1 "BACKUP" @@ -813,46 +813,42 @@ function _delete_old_files { if ! contains_trailing_slash "$dir"; then dir="${dir}/"; fi - if directory_exists "$dir"; then - log_info "Processing directory '$dir' for deletion of old files (keep: $keep_files)..." + log_info "Processing directory '$dir' for deletion of old files (keep: $keep_files)..." - # Get all files sorted by date - mapfile -t files < <(ls -dt "$dir"*) + # Get all files sorted by date + mapfile -t files < <(ls -dt "$dir") - if is_var_empty "${files[*]}"; then - log_warn "No files found in '$dir'. Skipping deletion of old files." - return 1 - fi + if is_var_empty "${files[*]}"; then + log_warn "No files found in '$dir'. Skipping deletion of old files." + return 1 + fi - local number_of_files="${#files[@]}" + local number_of_files="${#files[@]}" - log_debug "Files in '$dir' (number: $number_of_files):" - for file in "${files[@]}"; do - log_debug "$file" - done + log_debug "Files in '$dir' (number: $number_of_files):" + for file in "${files[@]}"; do + log_debug "$file" + done - if ((${#files[@]} > keep_files)); then - local files_to_delete=("${files[@]:keep_files}") + if ((${#files[@]} > keep_files)); then + local files_to_delete=("${files[@]:keep_files}") - log_info "Old files to delete (${#files_to_delete[@]} / $number_of_files):" - for file_to_delete in "${files_to_delete[@]}"; do - log_info "$file_to_delete" - done + log_info "Old files to delete (${#files_to_delete[@]} / $number_of_files):" + for file_to_delete in "${files_to_delete[@]}"; do + log_info "$file_to_delete" + done - for file_to_delete in "${files_to_delete[@]}"; do - log_info "Deleting old file '$file_to_delete'..." + for file_to_delete in "${files_to_delete[@]}"; do + log_info "Deleting old file '$file_to_delete'..." - if _is_dry_run_enabled; then - log_dry_run "rm -rf $file_to_delete" - else - rm -rf "$file_to_delete" || log_error "Failed to delete file: '$file_to_delete'" - fi + if _is_dry_run_enabled; then + log_dry_run "rm -rf $file_to_delete" + else + rm -rf "$file_to_delete" || log_error "Failed to delete file: '$file_to_delete'" + fi - log_notice "Old file deleted: '$file_to_delete'" - done - fi - else - log_notice "Directory '$dir' does not exist. Skipping deletion of old files." + log_notice "Old file deleted: '$file_to_delete'" + done fi } @@ -883,12 +879,17 @@ function delete_old_backups { return 1 fi - for sub_dir in "$backup_dir"/*; do - _delete_old_files "$sub_dir" "$keep_backups" || - { - log_warn "Deletion of old backups in '$sub_dir' failed" - return 1 - } + for sub_dir in "$backup_dir"/*/; do + if directory_exists "$sub_dir"; then + _delete_old_files "$sub_dir" "$keep_backups" || + { + log_warn "Deletion of old backups in '$sub_dir' failed" + return 1 + } + else + log_warn "No subdirectories found in '$backup_dir'. Skipping." + return 1 + fi done } From 8f57bd689d78a18f590499e583472a10ed09dcb7 Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 16:21:40 +0100 Subject: [PATCH 05/17] Improve console output when deleting old backup files --- src/domposy.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/domposy.bash b/src/domposy.bash index 443aee5..41d7f2f 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -887,7 +887,7 @@ function delete_old_backups { return 1 } else - log_warn "No subdirectories found in '$backup_dir'. Skipping." + log_warn "No subdirectories found in '$backup_dir'." return 1 fi done @@ -923,7 +923,7 @@ esac log_debug_delimiter_start 1 "DELETE OLD BACKUPS" delete_old_backups "$_ARG_BACKUP_DIR" "$_ARG_KEEP_BACKUPS" || - log_warn "Deletion of old backups failed" + log_warn "Deletion of old backups could not be completed" log_debug_delimiter_end 1 "DELETE OLD BACKUPS" show_docker_info From 37fa8bc1281686ec08c0d156ceb72c3c5ce70087 Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 16:29:05 +0100 Subject: [PATCH 06/17] Improve console output when deleting old backup files --- src/domposy.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/domposy.bash b/src/domposy.bash index 41d7f2f..daf9329 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -827,7 +827,7 @@ function _delete_old_files { log_debug "Files in '$dir' (number: $number_of_files):" for file in "${files[@]}"; do - log_debug "$file" + log_debug "- '$file'" done if ((${#files[@]} > keep_files)); then @@ -849,6 +849,8 @@ function _delete_old_files { log_notice "Old file deleted: '$file_to_delete'" done + else + log_notice "No files to delete. All files are kept. (number of files: $number_of_files | keep: $keep_files)" fi } From da6e18c8e5dbcf53d2bac349c13fb75209382105 Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 16:31:47 +0100 Subject: [PATCH 07/17] Fixes for deleting old backup files --- src/domposy.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/domposy.bash b/src/domposy.bash index daf9329..a567bad 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -816,7 +816,7 @@ function _delete_old_files { log_info "Processing directory '$dir' for deletion of old files (keep: $keep_files)..." # Get all files sorted by date - mapfile -t files < <(ls -dt "$dir") + mapfile -t files < <(ls -dt "$dir"*) if is_var_empty "${files[*]}"; then log_warn "No files found in '$dir'. Skipping deletion of old files." @@ -827,7 +827,7 @@ function _delete_old_files { log_debug "Files in '$dir' (number: $number_of_files):" for file in "${files[@]}"; do - log_debug "- '$file'" + log_debug "'$file'" done if ((${#files[@]} > keep_files)); then From 8f9f221ca0ad89e46336d9d18ff16292511b32db Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 16:38:10 +0100 Subject: [PATCH 08/17] Improve console output when deleting old backup files --- src/domposy.bash | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/domposy.bash b/src/domposy.bash index a567bad..f33aeb0 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -832,10 +832,11 @@ function _delete_old_files { if ((${#files[@]} > keep_files)); then local files_to_delete=("${files[@]:keep_files}") + local number_of_files_to_delete="${#files_to_delete[@]}" - log_info "Old files to delete (${#files_to_delete[@]} / $number_of_files):" + log_info "Old files to delete ($number_of_files_to_delete/$number_of_files):" for file_to_delete in "${files_to_delete[@]}"; do - log_info "$file_to_delete" + log_info "'$file_to_delete'" done for file_to_delete in "${files_to_delete[@]}"; do From 8940821e7a65eaa6516b78d760a02766eccb6cef Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 16:45:52 +0100 Subject: [PATCH 09/17] Fix double slash while deleting old files --- src/domposy.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/domposy.bash b/src/domposy.bash index f33aeb0..c1ff03d 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -862,6 +862,8 @@ function delete_old_backups { log_debug_var "delete_old_backups" "backup_dir" log_debug_var "delete_old_backups" "keep_backups" + if ! contains_trailing_slash "$backup_dir"; then backup_dir="${backup_dir}/"; fi + if directory_not_exists "$backup_dir"; then log_warn "Backup directory '$backup_dir' does not exist. Skipping deletion of old backups." return 1 @@ -882,7 +884,7 @@ function delete_old_backups { return 1 fi - for sub_dir in "$backup_dir"/*/; do + for sub_dir in "$backup_dir"*/; do if directory_exists "$sub_dir"; then _delete_old_files "$sub_dir" "$keep_backups" || { From fd0dea3b5d38e66aec076b419ca297b9b29f200c Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 17:12:37 +0100 Subject: [PATCH 10/17] Fix summary if invalid argument --- src/domposy.bash | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/domposy.bash b/src/domposy.bash index c1ff03d..2ae328f 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -500,6 +500,9 @@ function _process_arguments { ;; *) log_error "Invalid argument: '$1'. $message_with_help_information" + + # shellcheck disable=SC2034 + ENABLE_SUMMARY_ON_EXIT=false ;; esac shift From e238fcb138e588bd7f66855e00435946a9776ac9 Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 17:13:22 +0100 Subject: [PATCH 11/17] Increase minor version --- src/domposy.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domposy.bash b/src/domposy.bash index 2ae328f..b4bed31 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -53,7 +53,7 @@ # ░░ ░░ # ░░░░░░░░░░░░░░░░░░░░░▓▓▓░░░░░░░░░░░░░░░░░░░░░░ -declare -rx CONST_DOMPOSY_VERSION="2.0.0" +declare -rx CONST_DOMPOSY_VERSION="2.1.0" declare -rx CONST_DOMPOSY_NAME="domposy" # ░░░░░░░░░░░░░░░░░░░░░▓▓▓░░░░░░░░░░░░░░░░░░░░░░ From 2e6cfecaecb9b720e9e4124136d293d2911e5278 Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 17:15:04 +0100 Subject: [PATCH 12/17] Improve console output --- src/domposy.bash | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/domposy.bash b/src/domposy.bash index b4bed31..42306ec 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -603,7 +603,7 @@ function _create_backup_file_for_single_docker_compose_project { log_message_part_for_undoing_file_creations="Skipping further backup actions and undoing file creations." - log_info "TAR..." + log_debug "TAR..." if _is_dry_run_enabled; then log_dry_run "tar -cpf $tar_file_with_backup_dir -C $file_dir ." else @@ -616,7 +616,7 @@ function _create_backup_file_for_single_docker_compose_project { fi check_file_creation "$tar_file_with_backup_dir" - log_info "GZIP..." + log_debug "GZIP..." if _is_dry_run_enabled; then log_dry_run "gzip $tar_file_with_backup_dir" else @@ -783,13 +783,13 @@ function clean_docker_environment { function _process_remove { log_debug_delimiter_start 2 "REMOVE" - log_notice "Removing non-running containers..." + log_info "Removing non-running containers..." if _is_dry_run_enabled; then log_dry_run "docker container prune -f"; else log_notice "$(docker container prune -f)"; fi - log_notice "Removing unused docker images..." + log_info "Removing unused docker images..." if _is_dry_run_enabled; then log_dry_run "docker image prune -f"; else log_notice "$(docker image prune -f)"; fi - log_notice "Removing unused volumes..." + log_info "Removing unused volumes..." if _is_dry_run_enabled; then log_dry_run "docker volume prune -f"; else log_notice "$(docker volume prune -f)"; fi log_debug_delimiter_end 2 "REMOVE" From c1e8fd1646041471bc17e5fad0f1ecbf594b82dd Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 17:29:51 +0100 Subject: [PATCH 13/17] Fix subdirectory skipping when deleting old backups --- src/domposy.bash | 1 - 1 file changed, 1 deletion(-) diff --git a/src/domposy.bash b/src/domposy.bash index 42306ec..c4930cd 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -896,7 +896,6 @@ function delete_old_backups { } else log_warn "No subdirectories found in '$backup_dir'." - return 1 fi done } From 46c0aca6eceb8174dac0c629b5a9f94bfe215887 Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 17:33:34 +0100 Subject: [PATCH 14/17] Fix subdirectory skipping when deleting old backups --- src/domposy.bash | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/domposy.bash b/src/domposy.bash index c4930cd..a8b6c12 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -890,12 +890,10 @@ function delete_old_backups { for sub_dir in "$backup_dir"*/; do if directory_exists "$sub_dir"; then _delete_old_files "$sub_dir" "$keep_backups" || - { - log_warn "Deletion of old backups in '$sub_dir' failed" - return 1 - } + log_warn "Deletion of old backups in '$sub_dir' failed" else log_warn "No subdirectories found in '$backup_dir'." + return 1 fi done } From a29bad875bc5e8b129ebda408740d64364ca8122 Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 17:38:00 +0100 Subject: [PATCH 15/17] Improve console output --- src/domposy.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/domposy.bash b/src/domposy.bash index a8b6c12..dc8e956 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -274,7 +274,7 @@ function check_file_creation { # ░░░░░░░░░░░░░░░░░░░░░▓▓▓░░░░░░░░░░░░░░░░░░░░░░ function _check_permissions { - log_notice "Current user: '$(whoami)'" + log_info "Current user: '$(whoami)'" if [[ $(id -u) -ne 0 ]]; then if groups "$(whoami)" | grep -q '\bdocker\b'; then log_warn "You do not have root rights. If you want to create backups, they may not work properly." @@ -913,7 +913,7 @@ if _is_dry_run_enabled; then _disable_notifier; fi _check_permissions _set_docker_compose_cmd -log_notice "Current directory: '$(pwd)'" +log_info "Current directory: '$(pwd)'" show_docker_info From 2efcb1d0dce6b323611951291a66d3898bc0b19b Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 17:43:44 +0100 Subject: [PATCH 16/17] Improve setup.bash --- setup.bash | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/setup.bash b/setup.bash index 17ead7d..7eeb98d 100644 --- a/setup.bash +++ b/setup.bash @@ -108,11 +108,12 @@ function install { download_path="$CONST_GLOBAL_DOWNLOAD_PATH" bin_path="$CONST_GLOBAL_BIN_PATH" else + echo echo "You are not root." echo "The installation will be only available for the current user." echo "To install it globally, please run this script as root (sudo)." - read -r -p "Do you want to continue? [Y/n] " choice + read -r -p "Do you want to continue? [y/N] " choice if [[ "$choice" =~ ^[Yy]$ ]]; then download_path="$CONST_USER_DOWNLOAD_PATH" bin_path="$CONST_USER_BIN_PATH" @@ -129,6 +130,8 @@ function install { echo "Bin path: '$bin_path'" for repo_url in "${CONST_REPO_URLS[@]}"; do + echo + local app_name app_name=$(get_app_name_from_repo_url "$repo_url") @@ -205,10 +208,12 @@ function uninstall { echo "Bin path: '$bin_path'" for repo_url in "${CONST_REPO_URLS[@]}"; do + echo + app_name=$(get_app_name_from_repo_url "$repo_url") if [ -d "$download_path/$app_name" ] && [ -L "$bin_path/$app_name" ]; then - read -r -p "Do you want to uninstall '$app_name'? [Y/n] " choice + read -r -p "Do you want to uninstall '$app_name'? [y/N] " choice if [[ "$choice" =~ ^[Yy]$ ]]; then echo "Uninstalling '$app_name'..." From 09fd3ecc278c8426e4cdb6125ca1485881c57f5b Mon Sep 17 00:00:00 2001 From: Fabian Fuchs Date: Sat, 23 Nov 2024 17:52:58 +0100 Subject: [PATCH 17/17] Fix summary output if invalid argument --- src/domposy.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/domposy.bash b/src/domposy.bash index dc8e956..9487930 100644 --- a/src/domposy.bash +++ b/src/domposy.bash @@ -499,10 +499,10 @@ function _process_arguments { log_debug_var "_process_arguments" "SIMBASHLOG_NOTIFIER" ;; *) - log_error "Invalid argument: '$1'. $message_with_help_information" - # shellcheck disable=SC2034 ENABLE_SUMMARY_ON_EXIT=false + + log_error "Invalid argument: '$1'. $message_with_help_information" ;; esac shift