<?php
// Run from cron daily, for example:
// php /path/to/walkly/cron/db_backup.php
require __DIR__ . '/../api/bootstrap.php';

use App\Services\BackupService;
use App\Services\NotificationService;

try {
    $settings = new NotificationService();
    if ((int)$settings->setting('db_backup_enabled', '1') !== 1) {
        echo '[' . date('c') . "] Backups are disabled.\n";
        exit(0);
    }

    $backup = (new BackupService())->createDatabaseBackup(null);
    echo '[' . date('c') . '] Backup created: ' . $backup['file_name'] . "\n";
} catch (Throwable $e) {
    echo '[' . date('c') . '] Backup failed: ' . $e->getMessage() . "\n";
    exit(1);
}
