diff options
author | Filipp Lepalaan <filipp@mac.com> | 2015-12-08 18:39:07 +0200 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2015-12-08 18:39:07 +0200 |
commit | 60a99aa4b4f484bf4ab2eb378ee24a34d18aa3c8 (patch) | |
tree | 27a26bd8a3746be1bd8dbc5b84aee0092156a3ad /servo | |
parent | bd56bb9770c4c41959c72d0b29485820119d17e1 (diff) | |
download | Servo-60a99aa4b4f484bf4ab2eb378ee24a34d18aa3c8.tar.gz Servo-60a99aa4b4f484bf4ab2eb378ee24a34d18aa3c8.tar.bz2 Servo-60a99aa4b4f484bf4ab2eb378ee24a34d18aa3c8.zip |
Fix issues with portable export command
Diffstat (limited to 'servo')
-rw-r--r-- | servo/management/commands/backup.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/servo/management/commands/backup.py b/servo/management/commands/backup.py index 7951e82..9d63b27 100644 --- a/servo/management/commands/backup.py +++ b/servo/management/commands/backup.py @@ -4,8 +4,9 @@ import os import csv import shutil import subprocess -from datetime import date +from datetime import datetime from django.db import connection +from django.conf import settings from django.core.management.base import BaseCommand @@ -25,12 +26,20 @@ class Command(BaseCommand): help = 'Export this servo database in a portable format' def handle(self, *args, **options): - backupdir = 'backups/%s' % date.today().isoformat() - os.mkdir(backupdir) + # creates a folder, then dumps different portable tables as separate + # files to it, then compresses the folder and deletes it + if not os.path.exists(settings.BACKUP_DIR): + os.mkdir(settings.BACKUP_DIR) - cursor = connection.cursor() + dirname = datetime.now().strftime('%Y%m%d-%H%M') + backupdir = os.path.join(settings.BACKUP_DIR, dirname) + if not os.path.exists(backupdir): + os.mkdir(backupdir) + path = os.path.join(backupdir, 'notes.csv') + + cursor = connection.cursor() cursor.execute("""SELECT id, order_id, created_by_id, created_at, body FROM servo_note""") header = ['ID', 'ORDER_ID', 'USER_ID', 'CREATED_AT', 'NOTE'] |