import sqlite3 from django.conf import settings from django.core.management.base import BaseCommand, CommandError from filament.services import backup_database class Command(BaseCommand): help = "Erstellt einen konsistenten SQLite-Snapshot (auch im laufenden Betrieb)." def add_arguments(self, parser): parser.add_argument( "destination", help="Neue Sicherungsdatei; bestehende Dateien werden nie überschrieben." ) def handle(self, *args, **options): try: backup_database(settings.DATABASES["default"]["NAME"], options["destination"]) except (OSError, sqlite3.Error) as error: raise CommandError(f"Sicherung fehlgeschlagen: {error}") from error self.stdout.write(self.style.SUCCESS("SQLite-Sicherung erstellt und geprüft."))