6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 |
9 |
10 import os |
10 import os |
|
11 import subprocess |
11 from os.path import exists |
12 from os.path import exists |
12 from warnings import warn |
13 from warnings import warn |
13 from datetime import datetime, date, timedelta |
14 from datetime import datetime, date, timedelta |
14 |
15 |
15 import logilab.common as lgc |
16 import logilab.common as lgc |
171 |
172 |
172 def backup_to_file(self, backupfile): |
173 def backup_to_file(self, backupfile): |
173 cmd = self.dbhelper.backup_command(self.dbname, self.dbhost, |
174 cmd = self.dbhelper.backup_command(self.dbname, self.dbhost, |
174 self.dbuser, backupfile, |
175 self.dbuser, backupfile, |
175 keepownership=False) |
176 keepownership=False) |
176 if os.system(cmd): |
177 if subprocess.call(cmd): |
177 raise Exception('Failed command: %s' % cmd) |
178 raise Exception('Failed command: %s' % cmd) |
178 |
179 |
179 def restore_from_file(self, backupfile, confirm, drop=True): |
180 def restore_from_file(self, backupfile, confirm, drop=True): |
180 for cmd in self.dbhelper.restore_commands(self.dbname, self.dbhost, |
181 for cmd in self.dbhelper.restore_commands(self.dbname, self.dbhost, |
181 self.dbuser, backupfile, |
182 self.dbuser, backupfile, |
182 self.encoding, |
183 self.encoding, |
183 keepownership=False, |
184 keepownership=False, |
184 drop=drop): |
185 drop=drop): |
185 if os.system(cmd): |
186 if subprocess.call(cmd): |
186 print '-> Failed command: %s' % cmd |
187 print '-> Failed command: %s' % cmd |
187 if not confirm('Continue anyway?', default='n'): |
188 if not confirm('Continue anyway?', default='n'): |
188 raise Exception('Failed command: %s' % cmd) |
189 raise Exception('Failed command: %s' % cmd) |
189 |
190 |
190 def merge_args(self, args, query_args): |
191 def merge_args(self, args, query_args): |