17 lines
768 B
Python
17 lines
768 B
Python
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')}")
|