Scheduled Postgres backup, restore check, backup warnings in health, payment result logging

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 17:32:06 +03:30
parent a5feee053a
commit 7d81d193bd
11 changed files with 449 additions and 5 deletions

View File

View File

@@ -0,0 +1,16 @@
from django.core.management.base import BaseCommand, CommandError
from statuslog.backup import BackupError, run_backup
class Command(BaseCommand):
help = 'بکاپِ زمان‌بندی‌شده‌ی Postgres (pg_dump)، نگه‌داری ۷ روزه + ۴ هفته‌ای، هوکِ کپیِ بیرونی.'
def handle(self, *args, **opts):
try:
s = run_backup()
except BackupError as exc:
raise CommandError(str(exc))
self.stdout.write(f"{s['file']} {s['size_bytes'] // 1024} KB offsite={s['offsite']['state']}")
if s['offsite']['state'] == 'failed':
raise CommandError(f"بکاپِ محلی ساخته شد ولی کپیِ بیرونی شکست خورد: {s['offsite'].get('error')}")

View File

@@ -0,0 +1,17 @@
from django.core.management.base import BaseCommand, CommandError
from statuslog.backup import BackupError, run_verify
class Command(BaseCommand):
help = 'آخرین بکاپ را روی دیتابیسِ آزمایشیِ جدا بازیابی و شمارشِ جدول‌های پرداخت/ورود را می‌سنجد.'
def add_arguments(self, parser):
parser.add_argument('--file', default='', help='نامِ یک فایلِ مشخص در پوشه‌ی بکاپ (پیش‌فرض: آخرین).')
def handle(self, *args, **opts):
try:
r = run_verify(opts['file'])
except BackupError as exc:
raise CommandError(str(exc))
self.stdout.write(f"بازیابی از {r['file']} سالم بود: {r['counts']}")