38 import logging |
38 import logging |
39 import sys |
39 import sys |
40 |
40 |
41 from logilab.common.decorators import cached, clear_cache |
41 from logilab.common.decorators import cached, clear_cache |
42 from logilab.common.configuration import Method |
42 from logilab.common.configuration import Method |
43 from logilab.common.shellutils import getlogin |
43 from logilab.common.shellutils import getlogin, ASK |
44 from logilab.database import get_db_helper, sqlgen |
44 from logilab.database import get_db_helper, sqlgen |
45 |
45 |
46 from yams import schema2sql as y2sql |
46 from yams import schema2sql as y2sql |
47 from yams.schema import role_name |
47 from yams.schema import role_name |
48 |
48 |
1706 self.logger.critical('Unsupported format in archive: %s', formatinfo) |
1706 self.logger.critical('Unsupported format in archive: %s', formatinfo) |
1707 raise ValueError('Unknown format in %s: %s' % (backupfile, formatinfo)) |
1707 raise ValueError('Unknown format in %s: %s' % (backupfile, formatinfo)) |
1708 tables = archive.read('tables.txt').splitlines() |
1708 tables = archive.read('tables.txt').splitlines() |
1709 sequences = archive.read('sequences.txt').splitlines() |
1709 sequences = archive.read('sequences.txt').splitlines() |
1710 numranges = archive.read('numranges.txt').splitlines() |
1710 numranges = archive.read('numranges.txt').splitlines() |
1711 file_versions = self._parse_versions(archive.read('versions.txt')) |
1711 archive_versions = self._parse_versions(archive.read('versions.txt')) |
1712 versions = set(self._get_versions()) |
1712 db_versions = set(self._get_versions()) |
1713 if file_versions != versions: |
1713 if archive_versions != db_versions: |
1714 self.logger.critical('Unable to restore : versions do not match') |
1714 self.logger.critical('Restore warning : versions do not match') |
1715 self.logger.critical('Expected:\n%s', '\n'.join('%s : %s' % (cube, ver) |
1715 new_cubes = db_versions - archive_versions |
1716 for cube, ver in sorted(versions))) |
1716 if new_cubes: |
1717 self.logger.critical('Found:\n%s', '\n'.join('%s : %s' % (cube, ver) |
1717 self.logger.critical('In the db:\n%s', '\n'.join('%s : %s' % (cube, ver) |
1718 for cube, ver in sorted(file_versions))) |
1718 for cube, ver in sorted(new_cubes))) |
1719 raise ValueError('Unable to restore : versions do not match') |
1719 old_cubes = archive_versions - db_versions |
|
1720 if old_cubes: |
|
1721 self.logger.critical('In the archive:\n%s', '\n'.join('%s : %s' % (cube, ver) |
|
1722 for cube, ver in sorted(old_cubes))) |
|
1723 if not ASK.confirm('Versions mismatch: continue anyway ?', False): |
|
1724 raise ValueError('Unable to restore : versions do not match') |
1720 table_chunks = {} |
1725 table_chunks = {} |
1721 for name in archive.namelist(): |
1726 for name in archive.namelist(): |
1722 if not name.startswith('tables/'): |
1727 if not name.startswith('tables/'): |
1723 continue |
1728 continue |
1724 filename = basename(name) |
1729 filename = basename(name) |