#!/bin/bash

# Setup daily backup cron job at 3:00 AM

CRON_JOB="0 3 * * * cd /opt/v2-Docker && /usr/bin/python3 /opt/v2-Docker/v2_adminpanel/scheduled_backup.py >> /opt/v2-Docker/logs/cron_backup.log 2>&1"

# Check if cron job already exists
if crontab -l 2>/dev/null | grep -q "scheduled_backup.py"; then
    echo "Backup cron job already exists"
else
    # Add the cron job
    (crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -
    echo "Backup cron job added successfully"
fi

# Create logs directory if it doesn't exist
mkdir -p /opt/v2-Docker/logs

# Show current crontab
echo "Current crontab:"
crontab -l