From b09a4a45552a96f1cdfd3f22e7465da9856aa2d0 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Tue, 22 Sep 2015 00:00:50 +0300 Subject: Fixed dbbackup command --- servo/management/commands/dbbackup.py | 17 +++++++++-------- settings.py | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/servo/management/commands/dbbackup.py b/servo/management/commands/dbbackup.py index 068d1ce..4858b77 100644 --- a/servo/management/commands/dbbackup.py +++ b/servo/management/commands/dbbackup.py @@ -1,19 +1,20 @@ # -*- coding: utf-8 -*- +import os import sys -import logging -import subprocess +from time import strftime +from subprocess import call from django.conf import settings from django.core.management.base import BaseCommand class Command(BaseCommand): help = 'Backup this Servo database' + def handle(self, *args, **options): - if len(args) < 1: - print 'Usage: dbbackup file' - sys.exit(1) db = settings.DATABASES['default'] - pg_dump = subprocess.check_output(['which', 'pg_dump']).strip() - subprocess.call([pg_dump, '-Fc', db['NAME'], '-U', db['USER'], - '-f' , args[0]], env={'PGPASSWORD': db['PASSWORD']}) + fn = '%s_%s.pgdump' % (db['NAME'], strftime('%Y%m%d_%H%I')) + fn = os.path.join(settings.BACKUP_DIR, fn) + + call(['/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_dump', '-Fc', db['NAME'], '-U', db['USER'], + '-f' , fn], env={'PGPASSWORD': db['PASSWORD']}) diff --git a/settings.py b/settings.py index b20f158..0dbc590 100644 --- a/settings.py +++ b/settings.py @@ -215,6 +215,7 @@ REST_FRAMEWORK = { ENABLE_RULES = False TIMEZONE = 'Europe/Helsinki' +BACKUP_DIR = '/opt/servo/backups' GSX_CERT = 'uploads/settings/gsx_cert.pem' GSX_KEY = 'uploads/settings/gsx_key.pem' -- cgit v1.2.3