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:
0
statuslog/management/commands/__init__.py
Normal file
0
statuslog/management/commands/__init__.py
Normal file
16
statuslog/management/commands/backup_db.py
Normal file
16
statuslog/management/commands/backup_db.py
Normal 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')}")
|
||||
17
statuslog/management/commands/backup_verify.py
Normal file
17
statuslog/management/commands/backup_verify.py
Normal 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']}")
|
||||
Reference in New Issue
Block a user