Exemple #1
0
def remove_all_but_new_password_from_repo(computer, password):
    if is_windows():
        ret = subprocess.run(
            get_restic_list_passwords_command(),
            env=get_restic_env(computer, password),
            stdout=subprocess.PIPE,
            creationflags=CREATE_NO_WINDOW,
        ).stdout
    elif is_mac():
        ret = subprocess.run(
            get_restic_list_passwords_command(),
            env=get_restic_env(computer, password),
            stdout=subprocess.PIPE,
        ).stdout
    keys = json.loads(ret)
    for key in sorted(keys, key=lambda k: k["created"])[:-1]:
        if is_windows():
            subprocess.run(
                get_restic_delete_password_command(key["id"]),
                env=get_restic_env(computer, password),
                creationflags=CREATE_NO_WINDOW,
            )
        elif is_mac():
            subprocess.run(
                get_restic_delete_password_command(key["id"]),
                env=get_restic_env(computer, password),
            )
Exemple #2
0
    def __init__(self, main_window):
        QDialog.__init__(self)
        Ui_SettingsDialog.__init__(self)
        self.setupUi(self)

        self.logger = get_logger()
        self.main_window = main_window

        self.setWindowIcon(QIcon(LOGO_PATH))

        self.populate_settings()

        self.inclusions_add_button.pressed.connect(self.inclusions_add)
        self.inclusions_remove_button.pressed.connect(self.inclusions_remove)
        self.exclusions_add_button.pressed.connect(self.exclusions_add)
        self.exclusions_remove_button.pressed.connect(self.exclusions_remove)
        self.restore_different_computer_label.linkActivated.connect(
            self.restore_different_computer
        )
        self.inherit_backup_history_label.linkActivated.connect(
            self.inherit_backup_history
        )
        self.change_password_label.linkActivated.connect(self.change_password)
        self.save_button.pressed.connect(self.accept)

        if not self.has_other_computers():
            self.restore_different_computer_label.setVisible(False)
            self.inherit_backup_history_label.setVisible(False)

        if is_windows():
            self.backup_connected_file_systems_label.setVisible(False)
            self.backup_connected_file_systems_combo_box.setVisible(False)

        self.logger.info("Settings dialog displayed.")
Exemple #3
0
 def run(self):
     paths = get_selected_nodes(self.snapshot_tree_widget)
     computer = get_computer(self.email, self.password, self.computer_id)
     log_file = os.path.join(LOGS_PATH,
                             f"restore-{datetime.date.today()}.txt")
     with open(log_file, "a", encoding="utf-8") as log_f:
         if is_windows():
             ret = subprocess.run(
                 get_restic_restore_command(self.snapshot_id, self.target,
                                            paths),
                 env=get_restic_env(computer, self.password),
                 stderr=log_f,
                 creationflags=CREATE_NO_WINDOW,
             )
         elif is_mac():
             ret = subprocess.run(
                 get_restic_restore_command(self.snapshot_id, self.target,
                                            paths),
                 env=get_restic_env(computer, self.password),
                 stderr=log_f,
             )
     if ret.returncode == 0:
         self.logger.info("Restore successful.")
         self.restored.emit(self.target)
     else:
         self.logger.error("Restore failed.")
         self.failed.emit()
Exemple #4
0
def unlock_repo(computer, password):
    if is_windows():
        subprocess.run(
            get_restic_unlock_command(),
            env=get_restic_env(computer, password),
            creationflags=CREATE_NO_WINDOW,
        )
    elif is_mac():
        subprocess.run(
            get_restic_unlock_command(),
            env=get_restic_env(computer, password),
        )
def create_restic_repo_or_die(computer, password):
    if is_windows():
        ret = subprocess.run(
            get_restic_init_command(),
            env=get_restic_env(computer, password),
            creationflags=CREATE_NO_WINDOW,
        )
    elif is_mac():
        ret = subprocess.run(
            get_restic_init_command(),
            env=get_restic_env(computer, password),
        )
    if ret.returncode != 0:
        sys.exit()
Exemple #6
0
def add_new_password_to_repo(computer, old_password, password):
    with tempfile.TemporaryDirectory() as root:
        password_file = os.path.join(root, "password.txt")
        with open(password_file, "w", encoding="utf-8") as f:
            f.write(password)
        if is_windows():
            subprocess.run(
                get_restic_add_password_command(password_file),
                env=get_restic_env(computer, old_password),
                creationflags=CREATE_NO_WINDOW,
            )
        elif is_mac():
            subprocess.run(
                get_restic_add_password_command(password_file),
                env=get_restic_env(computer, old_password),
            )
def initialize_client(email, password):
    computer = create_computer_or_die(email, password)
    create_restic_repo_or_die(computer, password)
    config["meta"]["initialized"] = "yes"
    config["meta"]["email"] = email
    config["meta"]["computer_id"] = str(computer["id"])
    config["general"]["computer_name"] = get_computer_name()
    config["general"]["backup_schedule"] = "Automatic"
    if is_windows():
        config["inclusions"]["paths"] = DEFAULT_WIN_INCLUSIONS
        config["exclusions"]["paths"] = DEFAULT_WIN_EXCLUSIONS
    elif is_mac():
        config["inclusions"]["paths"] = DEFAULT_MAC_INCLUSIONS
        config["exclusions"]["paths"] = DEFAULT_MAC_EXCLUSIONS
    save_config()
    save_password_in_keyring(password)
    save_last_backed_up(
        "Creating your first backup. This window can be safely closed.")
    save_selected_files("0 files / 0 B")
    save_current_status("Idle")
    load_scripts()
Exemple #8
0
    def backup(self):
        password, computer = self.pre_backup()

        log_file = os.path.join(LOGS_PATH, f"backup-{datetime.date.today()}.txt")
        files_done, bytes_done, backup_finished = None, None, False
        with open(log_file, "a", encoding="utf-8") as log_f:
            restic_backup_command = get_restic_backup_command(
                config["general"]["max_upload_kibs"],
                config["general"]["backup_connected_file_systems"],
            )
            num_threads = config["general"]["num_backup_threads"]
            if is_windows():
                self.process = subprocess.Popen(
                    restic_backup_command,
                    env=get_restic_env(computer, password, num_threads),
                    stdout=subprocess.PIPE,
                    stderr=log_f,
                    creationflags=CREATE_NO_WINDOW,
                )
            elif is_mac():
                self.process = subprocess.Popen(
                    restic_backup_command,
                    env=get_restic_env(computer, password, num_threads),
                    stdout=subprocess.PIPE,
                    stderr=log_f,
                )
            self.logger.info(f'Backup command: {" ".join(restic_backup_command)}')
            while True:
                line = self.process.stdout.readline().rstrip()
                if not line:
                    break
                try:
                    message = json.loads(line)
                    files_done, bytes_done, backup_finished = self.handle_backup_output(
                        message, files_done, bytes_done
                    )
                except json.JSONDecodeError:
                    self.logger.error("Unable to decode json line.")

        self.post_backup(files_done, bytes_done, backup_finished)
Exemple #9
0
 def run(self):
     computer = get_computer(self.email, self.password, self.computer_id)
     if is_windows():
         snapshots = json.loads(
             subprocess.run(
                 get_restic_snapshots_command(),
                 env=get_restic_env(computer, self.password),
                 stdout=subprocess.PIPE,
                 creationflags=CREATE_NO_WINDOW,
             ).stdout)
     elif is_mac():
         snapshots = json.loads(
             subprocess.run(
                 get_restic_snapshots_command(),
                 env=get_restic_env(computer, self.password),
                 stdout=subprocess.PIPE,
             ).stdout)
     sorted_snapshots = sorted(snapshots,
                               key=lambda x: x["time"],
                               reverse=True)
     self.logger.info("Snapshots loaded.")
     self.loaded.emit(sorted_snapshots)
Exemple #10
0
 def run(self):
     computer = get_computer(self.email, self.password, self.computer_id)
     if is_windows():
         process = subprocess.run(
             get_restic_ls_command(self.snapshot_id),
             env=get_restic_env(computer, self.password),
             stdout=subprocess.PIPE,
             creationflags=CREATE_NO_WINDOW,
         )
     elif is_mac():
         process = subprocess.run(
             get_restic_ls_command(self.snapshot_id),
             env=get_restic_env(computer, self.password),
             stdout=subprocess.PIPE,
         )
     if process.returncode == 0:
         nodes = process.stdout.decode("utf-8").split("\n")
         tree = prepare_lazy_tree(nodes[1:-1])
         self.logger.info("Snapshot loaded.")
         self.loaded.emit(tree)
     else:
         self.logger.error("Snapshot load failed.")
         self.failed.emit()