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