Skip to content

Commit

Permalink
Merge pull request #4305 from SG345/dbbackup
Browse files Browse the repository at this point in the history
DB Backup: Fix backup_filepath referencing issue and error out invalid filepath
  • Loading branch information
aronasorman committed Aug 28, 2015
2 parents f732804 + 4251b3b commit 2e0f5ab
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions kalite/distributed/management/commands/restorebackup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys

from django.core.management.base import BaseCommand
from django.core.management import call_command
Expand All @@ -18,13 +19,16 @@ class Command(BaseCommand):
)

def handle(self, *args, **options):
backup_filepath = options['backup_filepath']
if(options['backup_filepath']):
if(os.path.isfile(backup_filepath)):
call_command('dbrestore', filepath=backup_filepath, database='default') #perform restore from the given filepath
else:
print 'The given file was not found.'
sys.exit(1)
else:
file_list = os.listdir(settings.BACKUP_DIRPATH) #Retrieve the filenames present in the BACKUP_DIRPATH
filelist = []
filenumber = 0
for i, f in enumerate(file_list):
print i, f.replace(".backup", "")
filelist.append(f)
Expand All @@ -37,5 +41,7 @@ def handle(self, *args, **options):
call_command('dbrestore', filepath=backup_filepath, database='default') #perform restore
except IndexError:
print 'Number option out of bounds.'
sys.exit(1)
else:
print 'No files available to restore.'
print 'No files available to restore.'
sys.exit(1)

0 comments on commit 2e0f5ab

Please sign in to comment.