#!/bin/bash

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
source "$SCRIPT_DIR/lib/common-functions.sh"

if [ "$EUID" -ne 0 ]; then
    print_error "This script must be run as root"
    exit 1
fi

print_banner "View Backup Status"

echo ""
echo -e "${BOLD}Acronis Backup Status${NC}"
echo ""
echo "Checking backup status..."
echo ""

# Check if acrocmd exists
if ! command -v acrocmd &>/dev/null; then
    echo -e "${YELLOW}acrocmd CLI tool not found${NC}"
    echo ""
    echo "Backup status is available through:"
    echo "  • Acronis web console (real-time status)"
    echo "  • Agent logs (see 'View Logs' option)"
    echo ""
    echo "To use CLI: acrocmd may need to be installed separately"
    echo ""
    press_enter
    exit 0
fi

# Show recent backup activities from logs
if [ -f "/var/lib/Acronis/BackupAndRecovery/MMS/mms.0.log" ]; then
    echo -e "${BOLD}Recent Backup Activity:${NC}"
    echo ""
    grep -i "backup.*completed\|backup.*started\|backup.*failed" /var/lib/Acronis/BackupAndRecovery/MMS/mms.0.log 2>/dev/null | tail -10
    echo ""
fi

echo "For detailed status, use:"
echo "  • Web console: Full backup history and status"
echo "  • acrocmd: Command-line status queries"
echo ""
press_enter
