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 |
1719 self.logger.critical('Unsupported format in archive: %s', formatinfo) |
1719 self.logger.critical('Unsupported format in archive: %s', formatinfo) |
1720 raise ValueError('Unknown format in %s: %s' % (backupfile, formatinfo)) |
1720 raise ValueError('Unknown format in %s: %s' % (backupfile, formatinfo)) |
1721 tables = archive.read('tables.txt').splitlines() |
1721 tables = archive.read('tables.txt').splitlines() |
1722 sequences = archive.read('sequences.txt').splitlines() |
1722 sequences = archive.read('sequences.txt').splitlines() |
1723 numranges = archive.read('numranges.txt').splitlines() |
1723 numranges = archive.read('numranges.txt').splitlines() |
1724 file_versions = self._parse_versions(archive.read('versions.txt')) |
1724 archive_versions = self._parse_versions(archive.read('versions.txt')) |
1725 versions = set(self._get_versions()) |
1725 db_versions = set(self._get_versions()) |
1726 if file_versions != versions: |
1726 if archive_versions != db_versions: |
1727 self.logger.critical('Unable to restore : versions do not match') |
1727 self.logger.critical('Restore warning: versions do not match') |
1728 self.logger.critical('Expected:\n%s', '\n'.join('%s : %s' % (cube, ver) |
1728 new_cubes = db_versions - archive_versions |
1729 for cube, ver in sorted(versions))) |
1729 if new_cubes: |
1730 self.logger.critical('Found:\n%s', '\n'.join('%s : %s' % (cube, ver) |
1730 self.logger.critical('In the db:\n%s', '\n'.join('%s: %s' % (cube, ver) |
1731 for cube, ver in sorted(file_versions))) |
1731 for cube, ver in sorted(new_cubes))) |
1732 raise ValueError('Unable to restore : versions do not match') |
1732 old_cubes = archive_versions - db_versions |
|
1733 if old_cubes: |
|
1734 self.logger.critical('In the archive:\n%s', '\n'.join('%s: %s' % (cube, ver) |
|
1735 for cube, ver in sorted(old_cubes))) |
|
1736 if not ASK.confirm('Versions mismatch: continue anyway ?', False): |
|
1737 raise ValueError('Unable to restore: versions do not match') |
1733 table_chunks = {} |
1738 table_chunks = {} |
1734 for name in archive.namelist(): |
1739 for name in archive.namelist(): |
1735 if not name.startswith('tables/'): |
1740 if not name.startswith('tables/'): |
1736 continue |
1741 continue |
1737 filename = basename(name) |
1742 filename = basename(name) |