backup_restore.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2019 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This library is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU Lesser General Public
  10. # License as published by the Free Software Foundation; either
  11. # version 2.1 of the License, or (at your option) any later version.
  12. #
  13. # This library is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. # Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public
  19. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  20. """
  21. Backup restore related functionality. Specifically:
  22. - prevent starting a domain currently being restored
  23. """
  24. import qubes.api
  25. import qubes.ext
  26. import qubes.vm.adminvm
  27. class BackupRestoreExtension(qubes.ext.Extension):
  28. # pylint: disable=too-few-public-methods
  29. @qubes.ext.handler('domain-pre-start')
  30. def on_domain_pre_start(self, vm, event, **kwargs):
  31. """Prevent starting a VM during restore"""
  32. # pylint: disable=unused-argument,no-self-use
  33. if 'backup-restore-in-progress' in vm.tags:
  34. raise qubes.exc.QubesVMError(
  35. vm, 'Restore of this domain in progress, cannot start')