From 4a467bbe1d6a19c8ec7b6ca0e40610dee5ac4e94 Mon Sep 17 00:00:00 2001 From: Arthur BOUDREAULT <arthur@lydra.fr> Date: Fri, 20 Jan 2023 13:40:29 +0100 Subject: [PATCH] refactor(ynh_backup): follow good practises for var naming / syntax --- roles/ynh_backup/templates/ynh_backup.sh.j2 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/roles/ynh_backup/templates/ynh_backup.sh.j2 b/roles/ynh_backup/templates/ynh_backup.sh.j2 index 6f74f4b..0f72831 100644 --- a/roles/ynh_backup/templates/ynh_backup.sh.j2 +++ b/roles/ynh_backup/templates/ynh_backup.sh.j2 @@ -1,7 +1,7 @@ #!/bin/bash today="$(date +%Y%m%d)" number_to_keep="{{ ynh_backup.number_days_to_keep | default("2") }}" -old_backup_list="$(yunohost backup list --output-as plain | head -n -"$number_to_keep")" +old_backup_list="$(yunohost backup list --output-as plain | head -n -${number_to_keep})" _good() { echo "SUCCESS: ${1}" && exit 0 @@ -12,16 +12,17 @@ _fail() { } _create_ynh_backup() { - echo "Backing up $today YunoHost data now." - yunohost backup create {% if ynh_backup.system | default(True) %}--system{% endif %}{% if ynh_backup.apps | default(True) %} --apps{% endif %}{% if ynh_backup.directory is defined %} --output-directory {{ ynh_backup.directory }}/backup_"$today" {% endif %} || _fail "can't create a backup" + echo "Backing up ${today} YunoHost data now." + yunohost backup create {% if ynh_backup.system | default(True) %}--system{% endif %}{% if ynh_backup.apps | default(True) %} --apps{% endif %}{% if ynh_backup.directory is defined %} --output-directory {{ ynh_backup.directory }}/backup_${today} {% endif %} || _fail "can't create a backup" } _prune_old_backup() { - if [ -n "$old_backup_list" ]; then - for backup in $old_backup_list; do - echo "Backup $backup is 2 days old or more. Purging it now." - yunohost backup delete "$backup" + if [ -n "${old_backup_list}" ]; then + for backup in ${old_backup_list}; do + echo "Backup ${backup} is 2 days old or more. Purging it now." + yunohost backup delete "${backup}" + rm -rf {{ ynh_backup.directory }}/backup_"${backup}" done _good "Purging of old backups completed." else -- GitLab