예제 #1
0
파일: repo_tab.py 프로젝트: borgbase/vorta
 def set_repos(self):
     count = self.repoSelector.count()
     for _ in range(
             4, count
     ):  # Repositories are listed after 4th entry in repoSelector
         self.repoSelector.removeItem(4)
     for repo in RepoModel.select():
         self.repoSelector.addItem(repo.url, repo.id)
예제 #2
0
 def process_result(self, result):
     if result['returncode'] == 0:
         repo_url, old_name = result['cmd'][-2].split('::')
         new_name = result['cmd'][-1]
         repo = RepoModel.get(url=repo_url)
         renamed_archive = ArchiveModel.get(name=old_name, repo=repo)
         renamed_archive.name = new_name
         renamed_archive.save()
예제 #3
0
파일: repo_tab.py 프로젝트: borgbase/vorta
    def process_new_repo(self, result):
        if result['returncode'] == 0:
            new_repo = RepoModel.get(url=result['params']['repo_url'])
            profile = self.profile()
            profile.repo = new_repo.id
            profile.save()

            self.set_repos()
            self.repoSelector.setCurrentIndex(self.repoSelector.count() - 1)
            self.repo_added.emit()
            self.init_repo_stats()
예제 #4
0
파일: init.py 프로젝트: borgbase/vorta
 def process_result(self, result):
     if result['returncode'] == 0:
         new_repo, created = RepoModel.get_or_create(
             url=result['params']['repo_url'],
             defaults={
                 'encryption':
                 result['params']['encryption'],
                 'extra_borg_arguments':
                 result['params']['extra_borg_arguments'],
             })
         if new_repo.encryption != 'none':
             self.keyring.set_password("vorta-repo", new_repo.url,
                                       result['params']['password'])
         new_repo.save()
예제 #5
0
def init_db(qapp, qtbot, tmpdir_factory):
    tmp_db = tmpdir_factory.mktemp('Vorta').join('settings.sqlite')
    mock_db = SqliteDatabase(str(tmp_db), pragmas={'journal_mode': 'wal', })
    vorta.store.connection.init_db(mock_db)

    default_profile = BackupProfileModel(name='Default')
    default_profile.save()

    new_repo = RepoModel(url='[email protected]:repo')
    new_repo.encryption = 'none'
    new_repo.save()

    default_profile.repo = new_repo.id
    default_profile.dont_run_on_metered_networks = False
    default_profile.validation_on = False
    default_profile.save()

    test_archive = ArchiveModel(snapshot_id='99999', name='test-archive', time=dt(2000, 1, 1, 0, 0), repo=1)
    test_archive.save()

    test_archive1 = ArchiveModel(snapshot_id='99998', name='test-archive1', time=dt(2000, 1, 1, 0, 0), repo=1)
    test_archive1.save()

    source_dir = SourceFileModel(dir='/tmp/another', repo=new_repo, dir_size=100, dir_files_count=18,
                                 path_isdir=True)
    source_dir.save()

    qapp.main_window.deleteLater()
    del qapp.main_window
    qapp.main_window = MainWindow(qapp)  # Re-open main window to apply mock data in UI

    yield

    qapp.jobs_manager.cancel_all_jobs()
    qtbot.waitUntil(lambda: not qapp.jobs_manager.is_worker_running(), **pytest._wait_defaults)
    mock_db.close()
예제 #6
0
    def validate(self):
        """Pre-flight check for valid input and borg binary."""
        if self.is_remote_repo and not re.match(r'.+:.+',
                                                self.values['repo_url']):
            self._set_status(
                self.tr(
                    'Please enter a valid repo URL or select a local path.'))
            return False

        if RepoModel.get_or_none(
                RepoModel.url == self.values['repo_url']) is not None:
            self._set_status(self.tr('This repo has already been added.'))
            return False

        return True
예제 #7
0
파일: test_repo.py 프로젝트: borgbase/vorta
def test_repo_unlink(qapp, qtbot):
    main = qapp.main_window
    tab = main.repoTab

    main.tabWidget.setCurrentIndex(0)
    qtbot.mouseClick(tab.repoRemoveToolbutton, QtCore.Qt.LeftButton)
    qtbot.waitUntil(lambda: tab.repoSelector.count() == 4,
                    **pytest._wait_defaults)
    assert RepoModel.select().count() == 0

    qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
    # -1 is the repo id in this test
    qtbot.waitUntil(
        lambda: main.progressText.text().startswith(
            'Add a backup repository first.'), **pytest._wait_defaults)
    assert main.progressText.text() == 'Add a backup repository first.'
예제 #8
0
파일: info_repo.py 프로젝트: borgbase/vorta
    def process_result(self, result):
        if result['returncode'] == 0:
            new_repo, _ = RepoModel.get_or_create(url=result['cmd'][-1])
            if 'cache' in result['data']:
                stats = result['data']['cache']['stats']
                new_repo.total_size = stats['total_size']
                new_repo.unique_csize = stats['unique_csize']
                new_repo.unique_size = stats['unique_size']
                new_repo.total_unique_chunks = stats['total_unique_chunks']
            if 'encryption' in result['data']:
                new_repo.encryption = result['data']['encryption']['mode']
            if new_repo.encryption != 'none':
                self.keyring.set_password("vorta-repo", new_repo.url,
                                          result['params']['password'])

            new_repo.extra_borg_arguments = result['params'][
                'extra_borg_arguments']

            new_repo.save()
예제 #9
0
파일: test_repo.py 프로젝트: borgbase/vorta
def test_create(qapp, borg_json_output, mocker, qtbot):
    main = qapp.main_window
    stdout, stderr = borg_json_output('create')
    popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
    mocker.patch.object(vorta.borg.borg_job,
                        'Popen',
                        return_value=popen_result)

    qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
    qtbot.waitUntil(
        lambda: main.progressText.text().startswith('Backup finished.'),
        **pytest._wait_defaults)
    qtbot.waitUntil(lambda: main.createStartBtn.isEnabled(),
                    **pytest._wait_defaults)
    assert EventLogModel.select().count() == 1
    assert ArchiveModel.select().count() == 3
    assert RepoModel.get(id=1).unique_size == 15520474
    assert main.createStartBtn.isEnabled()
    assert main.archiveTab.archiveTable.rowCount() == 3
    assert main.scheduleTab.logTableWidget.rowCount() == 1
예제 #10
0
파일: repo_tab.py 프로젝트: borgbase/vorta
    def repo_unlink_action(self):
        profile = self.profile()
        self.init_repo_stats()
        msg = QMessageBox()
        msg.setStandardButtons(QMessageBox.Ok)
        msg.setParent(self, QtCore.Qt.Sheet)
        selected_repo_id = self.repoSelector.currentData()
        selected_repo_index = self.repoSelector.currentIndex()
        if selected_repo_index > 2:
            repo = RepoModel.get(id=selected_repo_id)
            ArchiveModel.delete().where(
                ArchiveModel.repo_id == repo.id).execute()
            profile.repo = None
            profile.save()
            repo.delete_instance(recursive=True)  # This also deletes archives.
            self.repoSelector.setCurrentIndex(0)
            self.repoSelector.removeItem(selected_repo_index)
            msg.setWindowTitle(self.tr('Repository was Unlinked'))
            msg.setText(self.tr('You can always connect it again later.'))
            msg.show()

            self.repo_changed.emit()
            self.init_repo_stats()
예제 #11
0
    def to_db(self, overwrite_profile=False, overwrite_settings=True):
        profile_schema = self._profile_dict['SchemaVersion']['version']
        keyring = VortaKeyring.get_keyring()
        if SCHEMA_VERSION < profile_schema:
            raise VersionException()
        elif SCHEMA_VERSION > profile_schema:
            # Add model upgrading code here, only needed if not adding columns
            if profile_schema < 16:
                for sourcedir in self._profile_dict['SourceFileModel']:
                    sourcedir['dir_files_count'] = -1
                    sourcedir['dir_size'] = -1
                    sourcedir['path_isdir'] = False

        existing_profile = None
        if overwrite_profile:
            existing_profile = BackupProfileModel.get_or_none(
                BackupProfileModel.name == self.name)
            if existing_profile:
                self._profile_dict['id'] = existing_profile.id
        if not overwrite_profile or not existing_profile:
            # Guarantee uniqueness of ids
            while BackupProfileModel.get_or_none(
                    BackupProfileModel.id == self.id) is not None:
                self._profile_dict['id'] += 1

            # Add suffix incase names are the same
            if BackupProfileModel.get_or_none(
                    BackupProfileModel.name == self.name) is not None:
                suffix = 1
                while BackupProfileModel.get_or_none(
                        BackupProfileModel.name ==
                        f"{self.name}-{suffix}") is not None:
                    suffix += 1
                self._profile_dict['name'] = f"{self.name}-{suffix}"

        # Load existing repo or restore it
        if self._profile_dict['repo']:
            repo = RepoModel.get_or_none(RepoModel.url == self.repo_url)
            if repo is None:
                # Load repo from export
                repo = dict_to_model(RepoModel, self._profile_dict['repo'])
                repo.save(force_insert=True)
            self._profile_dict['repo'] = model_to_dict(repo)

        if self.repo_password:
            keyring.set_password('vorta-repo', self.repo_url,
                                 self.repo_password)
            del self._profile_dict['password']

        # Delete and recreate the tables to clear them
        if overwrite_settings:
            DB.drop_tables([SettingsModel, WifiSettingModel])
            DB.create_tables([SettingsModel, WifiSettingModel])
            SettingsModel.insert_many(
                self._profile_dict['SettingsModel']).execute()
            WifiSettingModel.insert_many(
                self._profile_dict['WifiSettingModel']).execute()

        # Set the profile ids to be match new profile
        for source in self._profile_dict['SourceFileModel']:
            source['profile'] = self.id
        SourceFileModel.insert_many(
            self._profile_dict['SourceFileModel']).execute()

        # Delete added dictionaries to make it match BackupProfileModel
        del self._profile_dict['SettingsModel']
        del self._profile_dict['SourceFileModel']
        del self._profile_dict['WifiSettingModel']
        del self._profile_dict['SchemaVersion']

        # dict to profile
        new_profile = dict_to_model(BackupProfileModel, self._profile_dict)
        if overwrite_profile and existing_profile:
            force_insert = False
        else:
            force_insert = True
        new_profile.save(force_insert=force_insert)
        init_db(
        )  # rerun db init code to perform the same operations on the new as as on application boot
        return new_profile