forked from ml-lab/DeepVideoAnalytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestore.py
More file actions
executable file
·26 lines (25 loc) · 1.08 KB
/
restore.py
File metadata and controls
executable file
·26 lines (25 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python
import django, os, sys, subprocess
sys.path.append(os.path.join(os.path.dirname(__file__),'../'))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
django.setup()
from django.conf import settings
if __name__ == '__main__':
path = sys.argv[-2]
media_dir = settings.MEDIA_ROOT
current_path = os.path.abspath(os.path.dirname(__file__))
command = ['unzip', '-o', '{}'.format(os.path.join(current_path, path))]
print ' '.join(command)
zipper = subprocess.Popen(command, cwd=media_dir)
zipper.communicate()
db = settings.DATABASES.values()[0]
pg = '/Users/aub3/PostgreSQL/pg96/bin/psql' if sys.platform == 'darwin' else 'psql'
with open('{}/postgres.dump'.format(media_dir)) as dumpfile:
dump = subprocess.Popen(
[pg, '--dbname',
'postgresql://{}:{}@{}:5432/{}'.format(db['USER'], db['PASSWORD'], db['HOST'], db['NAME'])],
cwd=media_dir, stdin=dumpfile)
dump.communicate()
print dump.returncode
os.remove('{}/postgres.dump'.format(media_dir))
print zipper.returncode