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()
def pre_backup(self): self.process = None self.backup_terminated = False self.initial_selected_files = get_selected_files() self.update_client_version() self.update_status(current_status="Preparing for backup") self.write_inclusion_exclusion_files() email = config["meta"]["email"] password = get_password_from_keyring() computer = get_computer(email, password, config["meta"]["computer_id"]) if not computer: raise ApiError() return password, computer
def inherit_backup_history(self): email = config["meta"]["email"] if verify_password(email): password = get_password_from_keyring() choose_computer_dialog = ChooseComputerDialog( email, password, "Choose the computer to inherit backup history from.", ) if choose_computer_dialog.exec(): computer_id = choose_computer_dialog.computer_id computer = get_computer(email, password, computer_id) computer_name = computer["name"] reply = QMessageBox.information( self, "Inherit Backup History?", f"You are about to inherit the backup history of the computer '{computer_name}'. Your current computer's backups will be replaced by the backups of '{computer_name}'. This is an irreversible operation. Continue?", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No, ) if reply == QMessageBox.StandardButton.Yes: self.main_window.stop_backup() current_computer_id = config["meta"]["computer_id"] inherit_computer(email, password, computer_id, current_computer_id) QMessageBox.information( self, "Inherited Backup History", f"Successfully inherited the backup history of '{computer_name}'. Note that settings like inclusions, exclusions, schedule, etc. were not inherited.", ) save_last_backed_up( "Backup history inherited. Creating first backup of this computer." ) if computer["last_backed_up_at"]: save_selected_files( format_selected_files( int(computer["last_backed_up_num_files"]), int(computer["last_backed_up_size"]), ) ) self.main_window.toggle_backup() self.reject()
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)
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()
import subprocess from blobbackup.util import RESTIC_PATH, get_restic_env, get_password_from_keyring from blobbackup.config import config from blobbackup.api import get_computer if __name__ == "__main__": email = config["meta"]["email"] password = get_password_from_keyring() computer_id = config["meta"]["computer_id"] computer = get_computer(email, password, computer_id) subprocess.run( [RESTIC_PATH, "stats", "--mode", "raw-data"], env=get_restic_env(computer, password), )
def snapshot_loaded(self, tree): computer = get_computer(self.email, self.password, self.computer_id) self.snapshot_tree_widget.initialize(tree, computer["name"]) self.reset_gui_state()