aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-09-22 00:00:50 +0300
committerFilipp Lepalaan <filipp@mac.com>2015-09-22 00:00:50 +0300
commitb09a4a45552a96f1cdfd3f22e7465da9856aa2d0 (patch)
treecd750bf424966774a56dfac8661d39cd583069ce
parent0942ce26e1341c25afd3a4addbc1adea6d5530f7 (diff)
downloadServo-b09a4a45552a96f1cdfd3f22e7465da9856aa2d0.tar.gz
Servo-b09a4a45552a96f1cdfd3f22e7465da9856aa2d0.tar.bz2
Servo-b09a4a45552a96f1cdfd3f22e7465da9856aa2d0.zip
Fixed dbbackup command
-rw-r--r--servo/management/commands/dbbackup.py17
-rw-r--r--settings.py1
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'