server/migractions.py
changeset 9456 a79e88aad555
parent 9451 c83a8ecb9bf5
child 9457 d5ed6efd6448
equal deleted inserted replaced
9455:62e89e696a3b 9456:a79e88aad555
   185             print '-> no backup done.'
   185             print '-> no backup done.'
   186             return
   186             return
   187         open(backupfile,'w').close() # kinda lock
   187         open(backupfile,'w').close() # kinda lock
   188         os.chmod(backupfile, 0600)
   188         os.chmod(backupfile, 0600)
   189         # backup
   189         # backup
       
   190         source = repo.system_source
   190         tmpdir = tempfile.mkdtemp()
   191         tmpdir = tempfile.mkdtemp()
   191         try:
   192         try:
   192             failed = False
   193             failed = False
   193             for source in repo.sources:
   194             try:
   194                 try:
   195                 source.backup(osp.join(tmpdir, source.uri), self.confirm, format=format)
   195                     source.backup(osp.join(tmpdir, source.uri), self.confirm, format=format)
   196             except Exception as ex:
   196                 except Exception as ex:
   197                 print '-> error trying to backup %s [%s]' % (source.uri, ex)
   197                     print '-> error trying to backup %s [%s]' % (source.uri, ex)
   198                 if not self.confirm('Continue anyway?', default='n'):
   198                     if not self.confirm('Continue anyway?', default='n'):
   199                     raise SystemExit(1)
   199                         raise SystemExit(1)
   200                 else:
   200                     else:
   201                     failed = True
   201                         failed = True
       
   202             with open(osp.join(tmpdir, 'format.txt'), 'w') as format_file:
   202             with open(osp.join(tmpdir, 'format.txt'), 'w') as format_file:
   203                 format_file.write('%s\n' % format)
   203                 format_file.write('%s\n' % format)
   204             with open(osp.join(tmpdir, 'versions.txt'), 'w') as version_file:
   204             with open(osp.join(tmpdir, 'versions.txt'), 'w') as version_file:
   205                 versions = repo.get_versions()
   205                 versions = repo.get_versions()
   206                 for cube, version in versions.iteritems():
   206                 for cube, version in versions.iteritems():
   245                 written_format = format_file.readline().strip()
   245                 written_format = format_file.readline().strip()
   246                 if written_format in ('portable', 'native'):
   246                 if written_format in ('portable', 'native'):
   247                     format = written_format
   247                     format = written_format
   248         self.config.init_cnxset_pool = False
   248         self.config.init_cnxset_pool = False
   249         repo = self.repo_connect()
   249         repo = self.repo_connect()
   250         for source in repo.sources:
   250         source = repo.system_source
   251             if systemonly and source.uri != 'system':
   251         try:
   252                 continue
   252             source.restore(osp.join(tmpdir, source.uri), self.confirm, drop, format)
   253             try:
   253         except Exception as exc:
   254                 source.restore(osp.join(tmpdir, source.uri), self.confirm, drop, format)
   254             print '-> error trying to restore %s [%s]' % (source.uri, exc)
   255             except Exception as exc:
   255             if not self.confirm('Continue anyway?', default='n'):
   256                 print '-> error trying to restore %s [%s]' % (source.uri, exc)
   256                 raise SystemExit(1)
   257                 if not self.confirm('Continue anyway?', default='n'):
       
   258                     raise SystemExit(1)
       
   259         shutil.rmtree(tmpdir)
   257         shutil.rmtree(tmpdir)
   260         # call hooks
   258         # call hooks
   261         repo.init_cnxset_pool()
   259         repo.init_cnxset_pool()
   262         repo.hm.call_hooks('server_restore', repo=repo, timestamp=backupfile)
   260         repo.hm.call_hooks('server_restore', repo=repo, timestamp=backupfile)
   263         print '-> database restored.'
   261         print '-> database restored.'