2017-12-10 21:14:14 +01:00
|
|
|
#!/usr/bin/python3
|
2012-01-31 14:29:13 +01:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
|
|
|
|
# Copyright (C) 2012 Marek Marczykowski <marmarek@mimuw.edu.pl>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
2017-11-06 21:06:30 +01:00
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
2012-01-31 14:29:13 +01:00
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2012-04-11 18:47:43 +02:00
|
|
|
import signal
|
2019-09-26 22:31:39 +02:00
|
|
|
from qubesadmin import exc
|
2017-12-10 21:14:14 +01:00
|
|
|
from qubesadmin import utils as admin_utils
|
2012-01-31 14:29:13 +01:00
|
|
|
|
2019-11-08 23:35:26 +01:00
|
|
|
from PyQt5 import QtCore, QtWidgets, QtGui # pylint: disable=import-error
|
2017-12-11 01:09:29 +01:00
|
|
|
from . import ui_backupdlg # pylint: disable=no-name-in-module
|
2017-12-10 22:11:07 +01:00
|
|
|
from . import multiselectwidget
|
2012-02-20 07:56:38 +01:00
|
|
|
|
2017-12-10 22:11:07 +01:00
|
|
|
from . import backup_utils
|
2017-12-10 21:14:14 +01:00
|
|
|
from . import utils
|
2018-10-20 18:34:15 +02:00
|
|
|
|
2017-12-10 21:14:14 +01:00
|
|
|
import grp
|
|
|
|
import pwd
|
|
|
|
import os
|
2019-10-24 04:52:04 +02:00
|
|
|
import shutil
|
2012-01-31 14:29:13 +01:00
|
|
|
|
2018-10-22 10:14:26 +02:00
|
|
|
# pylint: disable=too-few-public-methods
|
2018-10-20 18:34:15 +02:00
|
|
|
class BackupThread(QtCore.QThread):
|
|
|
|
def __init__(self, vm):
|
|
|
|
QtCore.QThread.__init__(self)
|
|
|
|
self.vm = vm
|
|
|
|
self.msg = None
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
msg = []
|
|
|
|
try:
|
|
|
|
if not self.vm.is_running():
|
|
|
|
self.vm.start()
|
2020-08-04 22:50:20 +02:00
|
|
|
except exc.QubesException:
|
2020-08-11 01:08:48 +02:00
|
|
|
# we may have insufficient permissions to ensure the qube is running
|
|
|
|
# let us hope for the best (worst case scenario, we will fail at the
|
|
|
|
# next step
|
2020-08-04 22:50:20 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
2018-10-20 18:34:15 +02:00
|
|
|
self.vm.app.qubesd_call(
|
|
|
|
'dom0', 'admin.backup.Execute',
|
|
|
|
backup_utils.get_profile_name(True))
|
2019-11-11 17:22:24 +01:00
|
|
|
except exc.BackupAlreadyRunningError:
|
|
|
|
msg.append("This backup is already in progress! Cancel it "
|
|
|
|
"or wait until it finishes.")
|
2018-10-20 18:34:15 +02:00
|
|
|
except Exception as ex: # pylint: disable=broad-except
|
|
|
|
msg.append(str(ex))
|
|
|
|
|
|
|
|
if msg:
|
|
|
|
self.msg = '\n'.join(msg)
|
2017-12-10 22:11:07 +01:00
|
|
|
|
2012-01-31 14:29:13 +01:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
class BackupVMsWindow(ui_backupdlg.Ui_Backup, QtWidgets.QWizard):
|
2018-10-20 18:34:15 +02:00
|
|
|
def __init__(self, qt_app, qubes_app, dispatcher, parent=None):
|
2020-08-23 02:53:36 +02:00
|
|
|
super().__init__(parent)
|
2012-01-31 14:29:13 +01:00
|
|
|
|
2018-01-06 02:08:34 +01:00
|
|
|
self.qt_app = qt_app
|
|
|
|
self.qubes_app = qubes_app
|
2012-01-31 14:29:13 +01:00
|
|
|
|
2013-11-28 03:50:17 +01:00
|
|
|
self.selected_vms = []
|
2018-10-20 23:01:35 +02:00
|
|
|
self.thread = None
|
2013-11-28 03:45:22 +01:00
|
|
|
|
2012-02-20 07:56:38 +01:00
|
|
|
self.setupUi(self)
|
2012-01-31 14:29:13 +01:00
|
|
|
|
2017-01-22 05:42:38 +01:00
|
|
|
self.progress_status.text = self.tr("Backup in progress...")
|
2013-09-28 12:33:56 +02:00
|
|
|
self.dir_line_edit.setReadOnly(False)
|
2012-01-31 14:29:13 +01:00
|
|
|
|
2017-12-10 22:11:07 +01:00
|
|
|
self.select_vms_widget = multiselectwidget.MultiSelectWidget(self)
|
2012-02-20 07:56:38 +01:00
|
|
|
self.verticalLayout.insertWidget(1, self.select_vms_widget)
|
2012-01-31 14:29:13 +01:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
self.currentIdChanged.connect(self.current_page_changed)
|
|
|
|
self.select_vms_widget.itemsRemoved.connect(self.vms_removed)
|
|
|
|
self.select_vms_widget.itemsAdded.connect(self.vms_added)
|
|
|
|
self.dir_line_edit.textChanged.connect(self.backup_location_changed)
|
2012-02-20 07:56:38 +01:00
|
|
|
|
|
|
|
self.select_vms_page.isComplete = self.has_selected_vms
|
2013-11-28 03:52:02 +01:00
|
|
|
self.select_dir_page.isComplete = self.has_selected_dir_and_pass
|
2017-12-10 21:14:14 +01:00
|
|
|
# FIXME
|
|
|
|
# this causes to run isComplete() twice, I don't know why
|
2020-08-11 01:08:48 +02:00
|
|
|
# update 2020-08: selectedChanged is emitted once,
|
|
|
|
# but completeChanged twice. Somehow.
|
2019-05-22 23:10:09 +02:00
|
|
|
self.select_vms_widget.selectedChanged.connect(
|
|
|
|
self.select_vms_page.completeChanged.emit)
|
|
|
|
self.passphrase_line_edit.textChanged.connect(
|
|
|
|
self.backup_location_changed)
|
|
|
|
self.passphrase_line_edit_verify.textChanged.connect(
|
|
|
|
self.backup_location_changed)
|
2013-11-28 03:52:02 +01:00
|
|
|
|
2012-04-04 01:40:13 +02:00
|
|
|
self.total_size = 0
|
2012-02-20 07:56:38 +01:00
|
|
|
|
2020-07-10 14:08:22 +02:00
|
|
|
utils.initialize_widget_with_vms(
|
|
|
|
widget=self.appvm_combobox,
|
|
|
|
qubes_app=self.qubes_app,
|
2018-02-20 19:22:57 +01:00
|
|
|
filter_function=(lambda vm:
|
|
|
|
vm.klass != 'TemplateVM'
|
2020-08-04 22:50:20 +02:00
|
|
|
and utils.is_running(vm, False)
|
|
|
|
and not utils.get_feature(vm, 'internal', False)),
|
2020-07-10 14:08:22 +02:00
|
|
|
allow_internal=True,
|
2017-12-10 21:14:14 +01:00
|
|
|
)
|
2020-07-10 14:08:22 +02:00
|
|
|
self.appvm_combobox.setCurrentIndex(
|
|
|
|
self.appvm_combobox.findText("dom0"))
|
2017-12-10 21:14:14 +01:00
|
|
|
|
2019-01-16 20:43:08 +01:00
|
|
|
self.unrecognized_config_label.setVisible(False)
|
|
|
|
self.load_settings()
|
|
|
|
|
2020-09-23 21:44:07 +02:00
|
|
|
self.show_passwd_button.pressed.connect(self.show_password)
|
|
|
|
self.show_passwd_button.released.connect(self.hide_password)
|
|
|
|
|
2019-01-16 20:43:08 +01:00
|
|
|
selected = self.vms_to_include()
|
2017-12-10 21:14:14 +01:00
|
|
|
self.__fill_vms_list__(selected)
|
2014-03-31 05:23:07 +02:00
|
|
|
|
2018-10-20 18:34:15 +02:00
|
|
|
# Connect backup events for progress_bar
|
|
|
|
self.progress_bar.setMinimum(0)
|
|
|
|
self.progress_bar.setMaximum(100)
|
|
|
|
self.dispatcher = dispatcher
|
|
|
|
dispatcher.add_handler('backup-progress', self.on_backup_progress)
|
|
|
|
|
2020-09-23 21:44:07 +02:00
|
|
|
def show_password(self):
|
|
|
|
self.passphrase_line_edit.setEchoMode(QtWidgets.QLineEdit.Normal)
|
|
|
|
self.show_passwd_button.setIcon(QtGui.QIcon(':/eye.svg'))
|
|
|
|
|
|
|
|
def hide_password(self):
|
|
|
|
self.passphrase_line_edit.setEchoMode(QtWidgets.QLineEdit.Password)
|
|
|
|
self.show_passwd_button.setIcon(QtGui.QIcon(':/eye-off.svg'))
|
|
|
|
|
2019-11-08 23:35:26 +01:00
|
|
|
def setup_application(self):
|
|
|
|
self.qt_app.setApplicationName(self.tr("Qubes Backup VMs"))
|
|
|
|
self.qt_app.setWindowIcon(QtGui.QIcon.fromTheme("qubes-manager"))
|
|
|
|
|
2018-10-20 18:34:15 +02:00
|
|
|
def on_backup_progress(self, __submitter, _event, **kwargs):
|
|
|
|
self.progress_bar.setValue(int(float(kwargs['progress'])))
|
|
|
|
|
2019-01-16 20:43:08 +01:00
|
|
|
def vms_to_include(self):
|
|
|
|
"""
|
|
|
|
Helper function that returns list of VMs with 'include_in_backups'
|
|
|
|
attribute set to True.
|
|
|
|
:return: list of VM names
|
|
|
|
"""
|
|
|
|
|
|
|
|
result = []
|
|
|
|
|
|
|
|
for domain in self.qubes_app.domains:
|
2020-08-11 01:08:48 +02:00
|
|
|
if getattr(domain, 'include_in_backups', False):
|
2019-01-16 20:43:08 +01:00
|
|
|
result.append(domain.name)
|
|
|
|
|
|
|
|
return result
|
2018-10-20 18:34:15 +02:00
|
|
|
|
2014-03-31 05:23:07 +02:00
|
|
|
def load_settings(self):
|
2018-01-06 02:08:34 +01:00
|
|
|
"""
|
|
|
|
Helper function that tries to load existing backup profile
|
|
|
|
(default path: /etc/qubes/backup/qubes-manager-backup.conf )
|
|
|
|
and then apply its contents to the Backup window.
|
2019-01-16 20:43:08 +01:00
|
|
|
Ignores listed VMs, to prioritize include_in_backups feature.
|
|
|
|
:return: None
|
2018-01-06 02:08:34 +01:00
|
|
|
"""
|
2017-12-10 21:14:14 +01:00
|
|
|
try:
|
2017-12-10 22:11:07 +01:00
|
|
|
profile_data = backup_utils.load_backup_profile()
|
2017-12-11 01:09:29 +01:00
|
|
|
except FileNotFoundError:
|
2017-12-11 00:50:40 +01:00
|
|
|
return
|
2017-12-11 01:09:29 +01:00
|
|
|
except exc.QubesException:
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
self, self.tr("Error loading backup profile"),
|
2017-12-11 00:50:40 +01:00
|
|
|
self.tr("Unable to load saved backup profile."))
|
2017-12-10 21:14:14 +01:00
|
|
|
return
|
|
|
|
if not profile_data:
|
|
|
|
return
|
|
|
|
|
|
|
|
if 'destination_vm' in profile_data:
|
|
|
|
dest_vm_name = profile_data['destination_vm']
|
|
|
|
dest_vm_idx = self.appvm_combobox.findText(dest_vm_name)
|
|
|
|
if dest_vm_idx > -1:
|
|
|
|
self.appvm_combobox.setCurrentIndex(dest_vm_idx)
|
2019-01-16 20:43:08 +01:00
|
|
|
else:
|
2020-08-06 21:52:42 +02:00
|
|
|
self.warning_running_label.setText(
|
|
|
|
"NOTE: Only running qubes are listed. The profile "
|
|
|
|
"lists {} as the destination qube, but it is not "
|
|
|
|
"currently running.".format(dest_vm_name))
|
2017-12-10 21:14:14 +01:00
|
|
|
|
|
|
|
if 'destination_path' in profile_data:
|
|
|
|
dest_path = profile_data['destination_path']
|
|
|
|
self.dir_line_edit.setText(dest_path)
|
|
|
|
|
|
|
|
if 'passphrase_text' in profile_data:
|
|
|
|
self.passphrase_line_edit.setText(profile_data['passphrase_text'])
|
|
|
|
self.passphrase_line_edit_verify.setText(
|
|
|
|
profile_data['passphrase_text'])
|
|
|
|
|
2017-12-11 02:34:31 +01:00
|
|
|
if 'compression' in profile_data:
|
|
|
|
self.compress_checkbox.setChecked(profile_data['compression'])
|
|
|
|
|
2017-12-10 23:17:39 +01:00
|
|
|
def save_settings(self, use_temp):
|
2018-01-06 02:08:34 +01:00
|
|
|
"""
|
|
|
|
Helper function that saves backup profile to either
|
|
|
|
/etc/qubes/backup/qubes-manager-backup.conf or
|
|
|
|
/etc/qubes/backup/qubes-manager-backup-tmp.conf
|
|
|
|
:param use_temp: whether to use temporary profile (True) or the default
|
|
|
|
backup profile (False)
|
|
|
|
"""
|
2017-12-10 21:14:14 +01:00
|
|
|
settings = {'destination_vm': self.appvm_combobox.currentText(),
|
|
|
|
'destination_path': self.dir_line_edit.text(),
|
|
|
|
'include': [vm.name for vm in self.selected_vms],
|
2017-12-11 02:34:31 +01:00
|
|
|
'passphrase_text': self.passphrase_line_edit.text(),
|
|
|
|
'compression': self.compress_checkbox.isChecked()}
|
2017-12-10 23:17:39 +01:00
|
|
|
|
|
|
|
backup_utils.write_backup_profile(settings, use_temp)
|
2012-03-29 23:26:16 +02:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
class VmListItem(QtWidgets.QListWidgetItem):
|
2017-12-11 00:50:40 +01:00
|
|
|
# pylint: disable=too-few-public-methods
|
2012-03-29 23:26:16 +02:00
|
|
|
def __init__(self, vm):
|
|
|
|
self.vm = vm
|
2020-08-11 01:08:48 +02:00
|
|
|
if vm.klass == 'AdminVM':
|
2012-04-04 01:40:13 +02:00
|
|
|
local_user = grp.getgrnam('qubes').gr_mem[0]
|
|
|
|
home_dir = pwd.getpwnam(local_user).pw_dir
|
2019-10-24 04:52:04 +02:00
|
|
|
self.size = shutil.disk_usage(home_dir)[1]
|
2012-04-04 01:40:13 +02:00
|
|
|
else:
|
2020-08-11 01:08:48 +02:00
|
|
|
try:
|
|
|
|
self.size = vm.get_disk_utilization()
|
|
|
|
except exc.QubesDaemonAccessError:
|
|
|
|
self.size = None
|
|
|
|
|
|
|
|
if self.size is not None:
|
|
|
|
text = vm.name + " (" + admin_utils.size_to_human(
|
|
|
|
self.size) + ")"
|
|
|
|
else:
|
|
|
|
text = vm.name + " (size unavailable)"
|
|
|
|
self.size = 0
|
|
|
|
super(BackupVMsWindow.VmListItem, self).__init__(text)
|
2012-04-04 01:40:13 +02:00
|
|
|
|
2017-12-10 21:14:14 +01:00
|
|
|
def __fill_vms_list__(self, selected=None):
|
2018-01-06 02:08:34 +01:00
|
|
|
for vm in self.qubes_app.domains:
|
2020-08-04 22:50:20 +02:00
|
|
|
if utils.get_feature(vm, 'internal', False):
|
2012-02-20 07:56:38 +01:00
|
|
|
continue
|
|
|
|
|
2012-03-29 23:26:16 +02:00
|
|
|
item = BackupVMsWindow.VmListItem(vm)
|
2017-12-10 21:14:14 +01:00
|
|
|
if (selected is None and
|
|
|
|
getattr(vm, 'include_in_backups', True)) \
|
|
|
|
or (selected and vm.name in selected):
|
2012-03-29 23:26:16 +02:00
|
|
|
self.select_vms_widget.selected_list.addItem(item)
|
2012-04-04 01:40:13 +02:00
|
|
|
self.total_size += item.size
|
2012-03-29 23:26:16 +02:00
|
|
|
else:
|
|
|
|
self.select_vms_widget.available_list.addItem(item)
|
2017-01-05 03:58:03 +01:00
|
|
|
self.select_vms_widget.available_list.sortItems()
|
|
|
|
self.select_vms_widget.selected_list.sortItems()
|
2017-12-10 21:14:14 +01:00
|
|
|
|
|
|
|
self.total_size_label.setText(
|
|
|
|
admin_utils.size_to_human(self.total_size))
|
2012-04-04 01:40:13 +02:00
|
|
|
|
|
|
|
def vms_added(self, items):
|
|
|
|
for i in items:
|
|
|
|
self.total_size += i.size
|
2017-12-10 21:14:14 +01:00
|
|
|
self.total_size_label.setText(
|
|
|
|
admin_utils.size_to_human(self.total_size))
|
2012-04-04 01:40:13 +02:00
|
|
|
|
|
|
|
def vms_removed(self, items):
|
|
|
|
for i in items:
|
|
|
|
self.total_size -= i.size
|
2017-12-10 21:14:14 +01:00
|
|
|
self.total_size_label.setText(
|
|
|
|
admin_utils.size_to_human(self.total_size))
|
2012-05-13 16:56:27 +02:00
|
|
|
|
2017-12-10 22:11:07 +01:00
|
|
|
@QtCore.pyqtSlot(name='on_select_path_button_clicked')
|
2012-02-20 07:56:38 +01:00
|
|
|
def select_path_button_clicked(self):
|
2017-12-10 22:11:07 +01:00
|
|
|
backup_utils.select_path_button_clicked(self)
|
2012-02-20 07:56:38 +01:00
|
|
|
|
|
|
|
def validateCurrentPage(self):
|
2017-12-11 00:50:40 +01:00
|
|
|
# pylint: disable=invalid-name
|
2012-02-20 07:56:38 +01:00
|
|
|
if self.currentPage() is self.select_vms_page:
|
2013-11-28 03:50:17 +01:00
|
|
|
|
|
|
|
self.selected_vms = []
|
2012-03-29 23:26:16 +02:00
|
|
|
for i in range(self.select_vms_widget.selected_list.count()):
|
2017-12-10 21:14:14 +01:00
|
|
|
self.selected_vms.append(
|
|
|
|
self.select_vms_widget.selected_list.item(i).vm)
|
2013-11-28 03:50:17 +01:00
|
|
|
|
2013-11-28 04:07:39 +01:00
|
|
|
elif self.currentPage() is self.select_dir_page:
|
2014-01-11 22:57:34 +01:00
|
|
|
backup_location = str(self.dir_line_edit.text())
|
|
|
|
if not backup_location:
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
self, self.tr("Wait!"),
|
2017-01-22 05:42:38 +01:00
|
|
|
self.tr("Enter backup target location first."))
|
2013-11-28 04:07:39 +01:00
|
|
|
return False
|
2018-02-20 19:22:57 +01:00
|
|
|
if self.appvm_combobox.currentText() == "dom0" \
|
2017-12-10 21:14:14 +01:00
|
|
|
and not os.path.isdir(backup_location):
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
self, self.tr("Wait!"),
|
2017-06-28 12:25:28 +02:00
|
|
|
self.tr("Selected directory do not exists or "
|
|
|
|
"not a directory (%s).") % backup_location)
|
2013-11-28 04:07:39 +01:00
|
|
|
return False
|
2017-12-11 01:09:29 +01:00
|
|
|
if not self.passphrase_line_edit.text():
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
self, self.tr("Wait!"),
|
2017-12-10 21:14:14 +01:00
|
|
|
self.tr("Enter passphrase for backup "
|
|
|
|
"encryption/verification first."))
|
2013-11-28 04:07:39 +01:00
|
|
|
return False
|
2017-12-10 21:14:14 +01:00
|
|
|
if self.passphrase_line_edit.text() !=\
|
|
|
|
self.passphrase_line_edit_verify.text():
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
self, self.tr("Wait!"),
|
2017-01-22 05:42:38 +01:00
|
|
|
self.tr("Enter the same passphrase in both fields."))
|
2013-11-28 04:07:39 +01:00
|
|
|
return False
|
|
|
|
|
2012-02-20 07:56:38 +01:00
|
|
|
return True
|
|
|
|
|
2018-01-06 02:08:34 +01:00
|
|
|
@staticmethod
|
|
|
|
def cleanup_temporary_files():
|
|
|
|
try:
|
|
|
|
os.remove(backup_utils.get_profile_path(use_temp=True))
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
2013-11-28 03:45:22 +01:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
def current_page_changed(self, page_id): # pylint: disable=unused-argument
|
2014-01-15 06:00:02 +01:00
|
|
|
old_sigchld_handler = signal.signal(signal.SIGCHLD, signal.SIG_DFL)
|
2012-02-20 07:56:38 +01:00
|
|
|
if self.currentPage() is self.confirm_page:
|
2013-09-28 12:33:56 +02:00
|
|
|
|
2018-01-06 02:08:34 +01:00
|
|
|
self.save_settings(use_temp=True)
|
2020-08-04 22:50:20 +02:00
|
|
|
try:
|
|
|
|
backup_summary = self.qubes_app.qubesd_call(
|
|
|
|
'dom0', 'admin.backup.Info',
|
|
|
|
backup_utils.get_profile_name(True)).decode()
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
2020-08-04 22:50:20 +02:00
|
|
|
backup_summary = "Failed to get backup summary: " \
|
|
|
|
"insufficient permissions"
|
2012-02-22 06:09:25 +01:00
|
|
|
|
2012-02-20 07:56:38 +01:00
|
|
|
self.textEdit.setReadOnly(True)
|
|
|
|
self.textEdit.setFontFamily("Monospace")
|
2020-08-04 22:50:20 +02:00
|
|
|
self.textEdit.setText(backup_summary)
|
2012-02-20 07:56:38 +01:00
|
|
|
|
|
|
|
elif self.currentPage() is self.commit_page:
|
2017-12-10 23:17:39 +01:00
|
|
|
|
|
|
|
if self.save_profile_checkbox.isChecked():
|
2018-01-06 02:08:34 +01:00
|
|
|
self.save_settings(use_temp=False)
|
2017-12-10 23:17:39 +01:00
|
|
|
|
2012-02-20 07:56:38 +01:00
|
|
|
self.button(self.FinishButton).setDisabled(True)
|
2014-05-15 03:06:51 +02:00
|
|
|
self.showFileDialog.setEnabled(
|
|
|
|
self.appvm_combobox.currentIndex() != 0)
|
|
|
|
self.showFileDialog.setChecked(self.showFileDialog.isEnabled()
|
|
|
|
and str(self.dir_line_edit.text())
|
|
|
|
.count("media/") > 0)
|
2018-10-20 18:34:15 +02:00
|
|
|
|
|
|
|
vm = self.qubes_app.domains[
|
|
|
|
self.appvm_combobox.currentText()]
|
|
|
|
|
|
|
|
self.thread = BackupThread(vm)
|
|
|
|
self.thread.finished.connect(self.backup_finished)
|
|
|
|
self.thread.start()
|
|
|
|
|
|
|
|
signal.signal(signal.SIGCHLD, old_sigchld_handler)
|
|
|
|
|
|
|
|
def backup_finished(self):
|
|
|
|
if self.thread.msg:
|
2019-10-23 18:18:39 +02:00
|
|
|
self.progress_status.setText(self.tr("Backup error"))
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.warning(
|
2019-10-23 18:18:39 +02:00
|
|
|
self, self.tr("Backup error"),
|
2018-10-20 18:34:15 +02:00
|
|
|
self.tr("ERROR: {}").format(
|
|
|
|
self.thread.msg))
|
2019-03-20 23:34:19 +01:00
|
|
|
self.button(self.CancelButton).setEnabled(False)
|
|
|
|
self.button(self.FinishButton).setEnabled(True)
|
|
|
|
self.cleanup_temporary_files()
|
|
|
|
|
2018-10-20 18:34:15 +02:00
|
|
|
else:
|
|
|
|
self.progress_bar.setValue(100)
|
|
|
|
self.progress_status.setText(self.tr("Backup finished."))
|
|
|
|
|
2015-03-31 05:40:53 +02:00
|
|
|
if self.showFileDialog.isChecked():
|
2014-05-15 03:06:51 +02:00
|
|
|
orig_text = self.progress_status.text
|
|
|
|
self.progress_status.setText(
|
2017-01-22 05:42:38 +01:00
|
|
|
orig_text + self.tr(
|
|
|
|
" Please unmount your backup volume and cancel "
|
|
|
|
"the file selection dialog."))
|
2017-12-11 02:04:06 +01:00
|
|
|
backup_utils.select_path_button_clicked(self, False, True)
|
2018-10-20 18:34:15 +02:00
|
|
|
|
2014-03-08 03:58:59 +01:00
|
|
|
self.button(self.CancelButton).setEnabled(False)
|
2012-02-20 07:56:38 +01:00
|
|
|
self.button(self.FinishButton).setEnabled(True)
|
2014-05-15 03:06:51 +02:00
|
|
|
self.showFileDialog.setEnabled(False)
|
2018-01-06 02:08:34 +01:00
|
|
|
self.cleanup_temporary_files()
|
2018-07-12 22:47:02 +02:00
|
|
|
|
|
|
|
# turn off only when backup was successful
|
2018-10-20 18:34:15 +02:00
|
|
|
if self.turn_off_checkbox.isChecked():
|
2018-07-12 22:47:02 +02:00
|
|
|
os.system('systemctl poweroff')
|
2018-07-12 23:31:30 +02:00
|
|
|
|
2012-03-02 02:50:12 +01:00
|
|
|
def reject(self):
|
2019-03-20 23:34:19 +01:00
|
|
|
if (self.currentPage() is self.commit_page) and \
|
|
|
|
self.button(self.CancelButton).isEnabled():
|
2019-10-17 21:22:01 +02:00
|
|
|
try:
|
|
|
|
self.qubes_app.qubesd_call(
|
|
|
|
'dom0', 'admin.backup.Cancel',
|
|
|
|
backup_utils.get_profile_name(True))
|
|
|
|
except exc.QubesException as ex:
|
|
|
|
QtWidgets.QMessageBox.warning(
|
|
|
|
self, self.tr("Error cancelling backup!"),
|
|
|
|
self.tr("ERROR: {}").format(str(ex)))
|
|
|
|
|
2018-11-25 18:53:31 +01:00
|
|
|
self.thread.wait()
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.warning(
|
2018-10-20 18:34:15 +02:00
|
|
|
self, self.tr("Backup aborted!"),
|
2019-10-23 18:18:39 +02:00
|
|
|
self.tr("ERROR: Aborted"))
|
2018-10-20 18:34:15 +02:00
|
|
|
|
|
|
|
self.cleanup_temporary_files()
|
|
|
|
self.done(0)
|
2012-03-02 02:50:12 +01:00
|
|
|
|
2012-02-20 07:56:38 +01:00
|
|
|
def has_selected_vms(self):
|
|
|
|
return self.select_vms_widget.selected_list.count() > 0
|
|
|
|
|
2013-11-28 03:52:02 +01:00
|
|
|
def has_selected_dir_and_pass(self):
|
2017-12-11 01:09:29 +01:00
|
|
|
if not self.passphrase_line_edit.text():
|
2013-11-28 03:52:02 +01:00
|
|
|
return False
|
2017-12-10 21:14:14 +01:00
|
|
|
if self.passphrase_line_edit.text() != \
|
|
|
|
self.passphrase_line_edit_verify.text():
|
2013-11-28 03:52:02 +01:00
|
|
|
return False
|
2014-01-11 22:57:34 +01:00
|
|
|
return len(self.dir_line_edit.text()) > 0
|
2012-01-31 14:29:13 +01:00
|
|
|
|
2017-12-10 21:14:14 +01:00
|
|
|
def backup_location_changed(self, new_dir=None):
|
2017-12-11 00:50:40 +01:00
|
|
|
# pylint: disable=unused-argument
|
2019-05-22 23:10:09 +02:00
|
|
|
self.select_dir_page.completeChanged.emit()
|
2012-02-20 07:56:38 +01:00
|
|
|
|
|
|
|
|
2018-10-20 18:34:15 +02:00
|
|
|
def main():
|
2019-11-08 23:35:26 +01:00
|
|
|
utils.run_asynchronous(BackupVMsWindow)
|
2012-01-31 14:29:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-12-10 21:14:14 +01:00
|
|
|
main()
|