2
2
3
3
import os , json
4
4
import frappe
5
+ from frappe .installer import extract_sql_gzip , import_db_from_sql
5
6
from frappe .utils import get_site_path , get_site_base_path , get_backups_path
6
7
from frappe .utils .backups import new_backup
7
8
@@ -34,8 +35,8 @@ def delete(self):
34
35
self .data = data
35
36
save_snapshots_data (data )
36
37
37
- def update (self , ddict ):
38
- self .data .update (ddict )
38
+ def update_path (self , path ):
39
+ self .data .update ({ self . name : path } )
39
40
save_snapshots_data (self .data )
40
41
41
42
def take (self ):
@@ -51,11 +52,13 @@ def take(self):
51
52
os .mkdir (snapshot_path )
52
53
53
54
os .rename (filename , snapshotname )
54
- self .data .update ({self .name : snapshotname })
55
- save_snapshots_data (self .data )
55
+ self .update_path (snapshotname )
56
56
57
57
def restore (self ):
58
- restore_from_file (self .get ())
58
+ path = str (self .get ())
59
+ restore_from_file (path )
60
+ if path .endswith ('sql.gz' ):
61
+ self .update_path (path [:- 3 ])
59
62
60
63
61
64
def get_snapshots_path ():
@@ -81,15 +84,13 @@ def get_snapshots_data():
81
84
return json .load (f )
82
85
83
86
84
- def restore_from_file (filename ):
85
- args = {
86
- "filename" : filename ,
87
- "user" : frappe .conf .db_name ,
88
- "password" : frappe .conf .db_password ,
89
- "db_name" : frappe .conf .db_name ,
90
- "db_host" : frappe .db .host ,
91
- }
87
+ def restore_from_file (sql_file_path ):
88
+ frappe .flags .in_install_db = True
89
+
90
+ if sql_file_path .endswith ('sql.gz' ):
91
+ sql_file_path = extract_sql_gzip (os .path .abspath (sql_file_path ))
92
+
93
+ import_db_from_sql (sql_file_path , True )
92
94
93
- cmd_string = """gunzip < %(filename)s | mysql -u %(user)s -p%(password)s %(db_name)s -h %(db_host)s""" % args
94
- frappe .utils .execute_in_shell (cmd_string )
95
+ frappe .flags .in_install_db = False
95
96
frappe .clear_cache ()
0 commit comments