479 server.run() |
479 server.run() |
480 |
480 |
481 |
481 |
482 def _remote_dump(host, appid, output, sudo=False): |
482 def _remote_dump(host, appid, output, sudo=False): |
483 # XXX generate unique/portable file name |
483 # XXX generate unique/portable file name |
484 dmpcmd = 'cubicweb-ctl db-dump -o /tmp/%s.dump %s' % (appid, appid) |
484 from datetime import date |
|
485 filename = '%s-%s.tgz' % (appid, date.today().strftime('%Y-%m-%d')) |
|
486 dmpcmd = 'cubicweb-ctl db-dump -o /tmp/%s %s' % (filename, appid) |
485 if sudo: |
487 if sudo: |
486 dmpcmd = 'sudo %s' % (dmpcmd) |
488 dmpcmd = 'sudo %s' % (dmpcmd) |
487 dmpcmd = 'ssh -t %s "%s"' % (host, dmpcmd) |
489 dmpcmd = 'ssh -t %s "%s"' % (host, dmpcmd) |
488 print dmpcmd |
490 print dmpcmd |
489 if os.system(dmpcmd): |
491 if os.system(dmpcmd): |
490 raise ExecutionError('Error while dumping the database') |
492 raise ExecutionError('Error while dumping the database') |
491 if output is None: |
493 if output is None: |
492 from datetime import date |
494 output = filename |
493 date = date.today().strftime('%Y-%m-%d') |
495 cmd = 'scp %s:/tmp/%s %s' % (host, filename, output) |
494 output = '%s-%s.dump' % (appid, date) |
|
495 cmd = 'scp %s:/tmp/%s.dump %s' % (host, appid, output) |
|
496 print cmd |
496 print cmd |
497 if os.system(cmd): |
497 if os.system(cmd): |
498 raise ExecutionError('Error while retrieving the dump') |
498 raise ExecutionError('Error while retrieving the dump at /tmp/%s' % filename) |
499 rmcmd = 'ssh -t %s "rm -f /tmp/%s.dump"' % (host, appid) |
499 rmcmd = 'ssh -t %s "rm -f /tmp/%s"' % (host, filename) |
500 print rmcmd |
500 print rmcmd |
501 if os.system(rmcmd) and not ASK.confirm( |
501 if os.system(rmcmd) and not ASK.confirm( |
502 'An error occured while deleting remote dump. Continue anyway?'): |
502 'An error occured while deleting remote dump at /tmp/%s. ' |
503 raise ExecutionError('Error while deleting remote dump') |
503 'Continue anyway?' % filename): |
|
504 raise ExecutionError('Error while deleting remote dump at /tmp/%s' % filename) |
504 |
505 |
505 def _local_dump(appid, output): |
506 def _local_dump(appid, output): |
506 config = ServerConfiguration.config_for(appid) |
507 config = ServerConfiguration.config_for(appid) |
507 # schema=1 to avoid unnecessary schema loading |
508 # schema=1 to avoid unnecessary schema loading |
508 mih = config.migration_handler(connect=False, schema=1, verbosity=1) |
509 mih = config.migration_handler(connect=False, schema=1, verbosity=1) |
667 |
668 |
668 def run(self, args): |
669 def run(self, args): |
669 import tempfile |
670 import tempfile |
670 srcappid = pop_arg(args, 1, msg='No source instance specified !') |
671 srcappid = pop_arg(args, 1, msg='No source instance specified !') |
671 destappid = pop_arg(args, msg='No destination instance specified !') |
672 destappid = pop_arg(args, msg='No destination instance specified !') |
672 # XXX -system necessary to match file name modified on source restore. |
673 output = tempfile.mkstemp(dir='/tmp/')[1] |
673 # should not have to expect this. |
|
674 _, output = tempfile.mkstemp('-system.sql') |
|
675 if ':' in srcappid: |
674 if ':' in srcappid: |
676 host, srcappid = srcappid.split(':') |
675 host, srcappid = srcappid.split(':') |
677 _remote_dump(host, srcappid, output, self.config.sudo) |
676 _remote_dump(host, srcappid, output, self.config.sudo) |
678 else: |
677 else: |
679 _local_dump(srcappid, output) |
678 _local_dump(srcappid, output) |