aboutsummaryrefslogtreecommitdiffstats
path: root/servo/management/commands/dumpdb.py
diff options
context:
space:
mode:
Diffstat (limited to 'servo/management/commands/dumpdb.py')
-rw-r--r--servo/management/commands/dumpdb.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/servo/management/commands/dumpdb.py b/servo/management/commands/dumpdb.py
new file mode 100644
index 0000000..c319336
--- /dev/null
+++ b/servo/management/commands/dumpdb.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+
+import os
+import os.path
+import subprocess
+from datetime import datetime
+from django.conf import settings
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+ help = "Dumps DB of this instance to specified file"
+
+ def handle(self, *args, **options):
+ s = settings.DATABASES['default']
+ db, user, pw = s['NAME'], s['USER'], s['PASSWORD']
+ fname = datetime.now().strftime('%Y%m%d_%H%M') + '.pgdump'
+ path = os.path.join(settings.BACKUP_DIR, fname)
+ os.putenv('PGPASSWORD', pw)
+ subprocess.call(['pg_dump', '-Fc', db, '-U', user, '-f', path])