server/migractions.py
branchstable
changeset 6323 a11c1e3c16c3
parent 6217 e2aeb40d5983
child 6333 e3994fcc21c3
child 6571 71b446d1cf93
equal deleted inserted replaced
6322:711e7e8c69e3 6323:a11c1e3c16c3
   203 
   203 
   204     def restore_database(self, backupfile, drop=True, systemonly=True,
   204     def restore_database(self, backupfile, drop=True, systemonly=True,
   205                          askconfirm=True):
   205                          askconfirm=True):
   206         # check
   206         # check
   207         if not osp.exists(backupfile):
   207         if not osp.exists(backupfile):
   208             raise Exception("Backup file %s doesn't exist" % backupfile)
   208             raise ExecutionError("Backup file %s doesn't exist" % backupfile)
   209         if askconfirm and not self.confirm('Restore %s database from %s ?'
   209         if askconfirm and not self.confirm('Restore %s database from %s ?'
   210                                            % (self.config.appid, backupfile)):
   210                                            % (self.config.appid, backupfile)):
   211             return
   211             return
   212         # unpack backup
   212         # unpack backup
   213         tmpdir = tempfile.mkdtemp()
   213         tmpdir = tempfile.mkdtemp()
   217             # assume restoring old backup
   217             # assume restoring old backup
   218             shutil.copy(backupfile, osp.join(tmpdir, 'system'))
   218             shutil.copy(backupfile, osp.join(tmpdir, 'system'))
   219         else:
   219         else:
   220             for name in bkup.getnames():
   220             for name in bkup.getnames():
   221                 if name[0] in '/.':
   221                 if name[0] in '/.':
   222                     raise Exception('Security check failed, path starts with "/" or "."')
   222                     raise ExecutionError('Security check failed, path starts with "/" or "."')
   223             bkup.close() # XXX seek error if not close+open !?!
   223             bkup.close() # XXX seek error if not close+open !?!
   224             bkup = tarfile.open(backupfile, 'r|gz')
   224             bkup = tarfile.open(backupfile, 'r|gz')
   225             bkup.extractall(path=tmpdir)
   225             bkup.extractall(path=tmpdir)
   226             bkup.close()
   226             bkup.close()
   227         self.config.open_connections_pools = False
   227         self.config.open_connections_pools = False
   789         specialized = eschema.specializes()
   789         specialized = eschema.specializes()
   790         if specialized:
   790         if specialized:
   791             try:
   791             try:
   792                 specialized.eid = instschema[specialized].eid
   792                 specialized.eid = instschema[specialized].eid
   793             except KeyError:
   793             except KeyError:
   794                 raise Exception('trying to add entity type but parent type is '
   794                 raise ExecutionError('trying to add entity type but parent type is '
   795                                 'not yet in the database schema')
   795                                      'not yet in the database schema')
   796             self.rqlexecall(ss.eschemaspecialize2rql(eschema), ask_confirm=confirm)
   796             self.rqlexecall(ss.eschemaspecialize2rql(eschema), ask_confirm=confirm)
   797         # register entity's attributes
   797         # register entity's attributes
   798         for rschema, attrschema in eschema.attribute_definitions():
   798         for rschema, attrschema in eschema.attribute_definitions():
   799             # ignore those meta relations, they will be automatically added
   799             # ignore those meta relations, they will be automatically added
   800             if rschema.type in META_RTYPES:
   800             if rschema.type in META_RTYPES: