From 60a99aa4b4f484bf4ab2eb378ee24a34d18aa3c8 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Tue, 8 Dec 2015 18:39:07 +0200 Subject: Fix issues with portable export command --- servo/management/commands/backup.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'servo') 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'] -- cgit v1.2.3