#!/bin/bash
BACKUP_DIR="/home/gaha6994/public_html/kimai/var/easy_backup"
cd "$BACKUP_DIR"

# Find all directories (excluding . and ..)
find . -maxdepth 1 -type d -name "2026-*" | while read dir; do
    if [ -d "$dir" ] && [ "$dir" != "." ] && [ "$dir" != ".." ]; then
        dirname=$(basename "$dir")
        zipfile="$dirname.zip"
        
        # Check if ZIP already exists
        if [ ! -f "$zipfile" ]; then
            echo "Converting $dirname to ZIP..."
            zip -r "$zipfile" "$dirname"
            if [ $? -eq 0 ]; then
                echo "✅ Created $zipfile"
                # Remove the folder after successful ZIP creation
                rm -rf "$dirname"
                echo "✅ Removed folder $dirname"
            else
                echo "❌ Failed to create ZIP for $dirname"
            fi
        fi
    fi
done
