Files
MathApp/statuslog/management/commands/backup_db.py

17 lines
768 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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')}")