feat(main): main
This commit is contained in:
12
core/management/commands/backup_now.py
Normal file
12
core/management/commands/backup_now.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from core.services.backups import create_backup_now
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Create a backup JSON under /Backups immediately."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
path = create_backup_now()
|
||||
self.stdout.write(self.style.SUCCESS(f"Backup created: {path}"))
|
||||
|
||||
30
core/management/commands/run_backup_worker.py
Normal file
30
core/management/commands/run_backup_worker.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import time
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from core.models import BackupSchedule
|
||||
from core.services.backups import create_backup_now, is_backup_due
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Continuously check backup schedule and run backups when due."
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
"--interval",
|
||||
type=int,
|
||||
default=60,
|
||||
help="Polling interval in seconds (default: 60).",
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
interval = options["interval"]
|
||||
self.stdout.write(self.style.SUCCESS(f"Starting backup worker (interval={interval}s)"))
|
||||
|
||||
while True:
|
||||
schedule = BackupSchedule.get_solo()
|
||||
if schedule.enabled and is_backup_due(schedule):
|
||||
path = create_backup_now()
|
||||
self.stdout.write(self.style.SUCCESS(f"Backup created: {path.name}"))
|
||||
time.sleep(interval)
|
||||
|
||||
Reference in New Issue
Block a user