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.schema import role_name |
46 from yams.schema import role_name |
47 |
47 |
48 from cubicweb import (UnknownEid, AuthenticationError, ValidationError, Binary, |
48 from cubicweb import (UnknownEid, AuthenticationError, ValidationError, Binary, |
1740 self.logger.critical('Unsupported format in archive: %s', formatinfo) |
1740 self.logger.critical('Unsupported format in archive: %s', formatinfo) |
1741 raise ValueError('Unknown format in %s: %s' % (backupfile, formatinfo)) |
1741 raise ValueError('Unknown format in %s: %s' % (backupfile, formatinfo)) |
1742 tables = archive.read('tables.txt').splitlines() |
1742 tables = archive.read('tables.txt').splitlines() |
1743 sequences = archive.read('sequences.txt').splitlines() |
1743 sequences = archive.read('sequences.txt').splitlines() |
1744 numranges = archive.read('numranges.txt').splitlines() |
1744 numranges = archive.read('numranges.txt').splitlines() |
1745 file_versions = self._parse_versions(archive.read('versions.txt')) |
1745 archive_versions = self._parse_versions(archive.read('versions.txt')) |
1746 versions = set(self._get_versions()) |
1746 db_versions = set(self._get_versions()) |
1747 if file_versions != versions: |
1747 if archive_versions != db_versions: |
1748 self.logger.critical('Unable to restore : versions do not match') |
1748 self.logger.critical('Restore warning: versions do not match') |
1749 self.logger.critical('Expected:\n%s', '\n'.join('%s : %s' % (cube, ver) |
1749 new_cubes = db_versions - archive_versions |
1750 for cube, ver in sorted(versions))) |
1750 if new_cubes: |
1751 self.logger.critical('Found:\n%s', '\n'.join('%s : %s' % (cube, ver) |
1751 self.logger.critical('In the db:\n%s', '\n'.join('%s: %s' % (cube, ver) |
1752 for cube, ver in sorted(file_versions))) |
1752 for cube, ver in sorted(new_cubes))) |
1753 raise ValueError('Unable to restore : versions do not match') |
1753 old_cubes = archive_versions - db_versions |
|
1754 if old_cubes: |
|
1755 self.logger.critical('In the archive:\n%s', '\n'.join('%s: %s' % (cube, ver) |
|
1756 for cube, ver in sorted(old_cubes))) |
|
1757 if not ASK.confirm('Versions mismatch: continue anyway ?', False): |
|
1758 raise ValueError('Unable to restore: versions do not match') |
1754 table_chunks = {} |
1759 table_chunks = {} |
1755 for name in archive.namelist(): |
1760 for name in archive.namelist(): |
1756 if not name.startswith('tables/'): |
1761 if not name.startswith('tables/'): |
1757 continue |
1762 continue |
1758 filename = basename(name) |
1763 filename = basename(name) |