diff options
-rw-r--r-- | servo/management/commands/dbbackup.py | 17 | ||||
-rw-r--r-- | 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' |