Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/butter_backup/backup_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def do_backup(self, mount_dir: Path) -> None:
files_dest.mkdir(parents=True, exist_ok=True)
for src in self.config.Files:
self.rsync_file(src, files_dest)
self.sync_filesystem_changes(mount_dir)

@staticmethod
def get_source_snapshot(root: Path) -> Path:
Expand Down Expand Up @@ -108,11 +107,6 @@ def rsync_file(src: Path, dest: Path) -> None:
cmd: sh.StrPathList = ["sudo", "rsync", "-ax", "--inplace", src, dest]
sh.run_cmd(cmd=cmd)

@staticmethod
def sync_filesystem_changes(mount_dir: Path) -> None:
sync_cmd: sh.StrPathList = ["sudo", "btrfs", "filesystem", "sync", mount_dir]
sh.run_cmd(cmd=sync_cmd)

@staticmethod
def rsync_folder(
src: Path, dest: Path, maybe_exclude_patterns: Path | None
Expand Down Expand Up @@ -153,11 +147,6 @@ def adapt_ownership(backup_repository: Path) -> None:
)
sdm.chown(backup_repository, user, group, recursive=True)

@staticmethod
def sync_filesystem_changes(mount_dir: Path) -> None:
sync_cmd: sh.StrPathList = ["sudo", "sync", "-f", mount_dir]
sh.run_cmd(cmd=sync_cmd)

def copy_files(self, backup_repository: Path) -> None:
restic_cmd: sh.StrPathList = [
"sudo",
Expand All @@ -171,4 +160,3 @@ def copy_files(self, backup_repository: Path) -> None:
restic_cmd.extend(["--exclude-file", self.config.ExcludePatternsFile])
restic_cmd.extend(list(self.config.FilesAndFolders))
sh.pipe_pass_cmd_to_real_cmd(self.config.RepositoryPassCmd, restic_cmd)
self.sync_filesystem_changes(backup_repository)
24 changes: 14 additions & 10 deletions src/butter_backup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,21 @@ def close(config: Path = CONFIG_OPTION, verbose: int = VERBOSITY_OPTION) -> None
configurations = cp.parse_configuration(config.read_text())
mounted_devices = sdm.get_mounted_devices()
for cfg in configurations:
mapped_device = str(cfg.map_name())
if cfg.device().exists() and mapped_device in mounted_devices:
mount_dirs = mounted_devices[mapped_device]
if len(mount_dirs) != 1:
# TODO introduce custom exception
raise ValueError(
"Got several possible mount points. Expected exactly 1!"
map_name = cfg.map_name()
map_name_as_str = str(map_name)
if cfg.device().exists() and map_name_as_str in mounted_devices:
mount_dirs = mounted_devices[map_name_as_str]
num_mount_dirs = len(mount_dirs)
if num_mount_dirs != 1:
logger.error(
"Got {num_mount_dirs} mount points for device {device}. Expected"
" exactly 1! Skipping device.",
num_mount_dirs=num_mount_dirs,
device=cfg.Name,
)
mount_dir = next(iter(mount_dirs))
sdm.unmount_device(mount_dir)
sdm.close_decrypted_device(Path(mapped_device))
continue
sdm.unmount_device(map_name)
sdm.close_decrypted_device(map_name)


@app.command()
Expand Down
Loading