197 |
197 |
198 def backup_to_file(self, backupfile, confirm): |
198 def backup_to_file(self, backupfile, confirm): |
199 cmd = self.dbhelper.backup_command(self.dbname, self.dbhost, |
199 cmd = self.dbhelper.backup_command(self.dbname, self.dbhost, |
200 self.dbuser, backupfile, |
200 self.dbuser, backupfile, |
201 keepownership=False) |
201 keepownership=False) |
202 while True: |
202 backupdir = os.path.dirname(backupfile) |
203 print cmd |
203 if not os.path.exists(backupdir): |
204 if os.system(cmd): |
204 if confirm('%s does not exist. Create it?' % backupdir, |
205 print '-> error while backuping the base' |
205 abort=False, shell=False): |
206 answer = confirm('Continue anyway?', |
206 os.mkdir(backupdir) |
207 shell=False, abort=False, retry=True) |
|
208 if not answer: |
|
209 raise SystemExit(1) |
|
210 if answer == 1: # 1: continue, 2: retry |
|
211 break |
|
212 else: |
207 else: |
213 print '-> backup file', backupfile |
208 print '-> failed to backup instance' |
214 restrict_perms_to_user(backupfile, self.info) |
209 return |
215 break |
210 if os.system(cmd): |
|
211 print '-> error trying to backup with command', cmd |
|
212 if not confirm('Continue anyway?', default_is_yes=False): |
|
213 raise SystemExit(1) |
|
214 else: |
|
215 print '-> backup file', backupfile |
|
216 restrict_perms_to_user(backupfile, self.info) |
216 |
217 |
217 def restore_from_file(self, backupfile, confirm, drop=True): |
218 def restore_from_file(self, backupfile, confirm, drop=True): |
218 for cmd in self.dbhelper.restore_commands(self.dbname, self.dbhost, |
219 for cmd in self.dbhelper.restore_commands(self.dbname, self.dbhost, |
219 self.dbuser, backupfile, |
220 self.dbuser, backupfile, |
220 self.encoding, |
221 self.encoding, |
221 keepownership=False, |
222 keepownership=False, |
222 drop=drop): |
223 drop=drop): |
223 while True: |
224 while True: |
224 print cmd |
225 print cmd |
225 if os.system(cmd): |
226 if os.system(cmd): |
226 print 'error while restoring the base' |
227 print '-> error while restoring the base' |
227 print 'OOOOOPS', confirm |
228 answer = confirm('Continue anyway?', |
228 answer = confirm('continue anyway?', |
|
229 shell=False, abort=False, retry=True) |
229 shell=False, abort=False, retry=True) |
230 if not answer: |
230 if not answer: |
231 raise SystemExit(1) |
231 raise SystemExit(1) |
232 if answer == 1: # 1: continue, 2: retry |
232 if answer == 1: # 1: continue, 2: retry |
233 break |
233 break |
234 else: |
234 else: |
235 break |
235 break |
236 print 'database restored' |
236 print '-> database restored.' |
237 |
237 |
238 def merge_args(self, args, query_args): |
238 def merge_args(self, args, query_args): |
239 if args is not None: |
239 if args is not None: |
240 args = dict(args) |
240 args = dict(args) |
241 for key, val in args.items(): |
241 for key, val in args.items(): |