Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions remove-old-wordpress-backups/remove-wordpress-backups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,27 +277,53 @@ scan_domains() {
done
}

# Function to build the plain-text per-domain report used both on-screen and in the email
# Function to build the plain-text report used both on-screen and in the email:
# a summary line, a "removed" section (only domains with something removed),
# and a compact found-backup-count table for every domain.
build_report() {
local action="Removed"
[ "${DRY_RUN}" = "true" ] && action="Would remove (dry-run)"
local action="removed" action_title="Removed"
if [ "${DRY_RUN}" = "true" ]; then
action="would be removed"
action_title="Would remove (dry-run)"
fi

local i domain found removed_files removed_count
local total_found=0 total_removed=0
local -a removed_section=() counts_section=()

for i in "${!DOMAIN_NAMES[@]}"; do
domain="${DOMAIN_NAMES[$i]}"
found="${DOMAIN_FOUND[$i]}"
removed_files="${DOMAIN_REMOVED_FILES[$i]}"
removed_count=0
[ -n "${removed_files}" ] && removed_count=$(printf '%s' "${removed_files}" | grep -c .)

echo "Domain: ${domain}"
echo " Backups found: ${found}"
echo " ${action}: ${removed_count}"
total_found=$((total_found + found))
total_removed=$((total_removed + removed_count))

counts_section+=("$(printf ' %-45s %d' "${domain}" "${found}")")

if [ "${removed_count}" -gt 0 ]; then
printf '%s' "${removed_files}" | sed '/^$/d;s/^/ - /'
removed_section+=("${domain} - ${action_title}: ${removed_count}")
while IFS= read -r f; do
[ -n "${f}" ] && removed_section+=(" - ${f}")
done <<<"${removed_files}"
fi
echo ""
done

echo "Summary: ${#DOMAIN_NAMES[@]} domain(s) scanned, ${total_found} backup(s) found, ${total_removed} ${action}"
echo ""

echo "Backups ${action} by domain:"
if [ "${#removed_section[@]}" -eq 0 ]; then
echo " (none)"
else
printf '%s\n' "${removed_section[@]}"
fi
echo ""

echo "Backups found by domain:"
printf '%s\n' "${counts_section[@]}"
}

# Function to send the report via an SMTP relay using curl, for servers with no local MTA.
Expand Down
Loading