--- a/server/serverctl.py Thu Apr 21 16:33:55 2011 +0200
+++ b/server/serverctl.py Thu Apr 21 12:35:41 2011 +0200
@@ -691,19 +691,20 @@
'Continue anyway?' % filename):
raise ExecutionError('Error while deleting remote dump at /tmp/%s' % filename)
-def _local_dump(appid, output):
+
+def _local_dump(appid, output, format='native'):
config = ServerConfiguration.config_for(appid)
config.quick_start = True
mih = config.migration_handler(connect=False, verbosity=1)
- mih.backup_database(output, askconfirm=False)
+ mih.backup_database(output, askconfirm=False, format=format)
mih.shutdown()
-def _local_restore(appid, backupfile, drop, systemonly=True):
+def _local_restore(appid, backupfile, drop, systemonly=True, format='native'):
config = ServerConfiguration.config_for(appid)
config.verbosity = 1 # else we won't be asked for confirmation on problems
config.quick_start = True
mih = config.migration_handler(connect=False, verbosity=1)
- mih.restore_database(backupfile, drop, systemonly, askconfirm=False)
+ mih.restore_database(backupfile, drop, systemonly, askconfirm=False, format=format)
repo = mih.repo_connect()
# version of the database
dbversions = repo.get_versions()
@@ -777,6 +778,12 @@
'default' : False,
'help': 'Use sudo on the remote host.'}
),
+ ('format',
+ {'short': 'f', 'default': 'native', 'type': 'choice',
+ 'choices': ('native', 'portable'),
+ 'help': '"native" format uses db backend utilities to dump the database. '
+ '"portable" format uses a database independent format'}
+ ),
)
def run(self, args):
@@ -785,7 +792,9 @@
host, appid = appid.split(':')
_remote_dump(host, appid, self.config.output, self.config.sudo)
else:
- _local_dump(appid, self.config.output)
+ _local_dump(appid, self.config.output, format=self.config.format)
+
+
class DBRestoreCommand(Command):
@@ -811,13 +820,33 @@
'instance data. In that case, <backupfile> is expected to be the '
'timestamp of the backup to restore, not a file'}
),
+ ('format',
+ {'short': 'f', 'default': 'native', 'type': 'choice',
+ 'choices': ('native', 'portable'),
+ 'help': 'the format used when dumping the database'}),
)
def run(self, args):
appid, backupfile = args
+ if self.config.format == 'portable':
+ # we need to ensure a DB exist before restoring from portable format
+ if not self.config.no_drop:
+ try:
+ CWCTL.run(['db-create', '--automatic', appid])
+ except SystemExit, exc:
+ # continue if the command exited with status 0 (success)
+ if exc.code:
+ raise
_local_restore(appid, backupfile,
drop=not self.config.no_drop,
- systemonly=not self.config.restore_all)
+ systemonly=not self.config.restore_all,
+ format=self.config.format)
+ if self.config.format == 'portable':
+ try:
+ CWCTL.run(['db-rebuild-fti', appid])
+ except SystemExit, exc:
+ if exc.code:
+ raise
class DBCopyCommand(Command):
@@ -850,6 +879,12 @@
'default' : False,
'help': 'Use sudo on the remote host.'}
),
+ ('format',
+ {'short': 'f', 'default': 'native', 'type': 'choice',
+ 'choices': ('native', 'portable'),
+ 'help': '"native" format uses db backend utilities to dump the database. '
+ '"portable" format uses a database independent format'}
+ ),
)
def run(self, args):
@@ -861,8 +896,9 @@
host, srcappid = srcappid.split(':')
_remote_dump(host, srcappid, output, self.config.sudo)
else:
- _local_dump(srcappid, output)
- _local_restore(destappid, output, not self.config.no_drop)
+ _local_dump(srcappid, output, format=self.config.format)
+ _local_restore(destappid, output, not self.config.no_drop,
+ self.config.format)
if self.config.keep_dump:
print '-> you can get the dump file at', output
else: