Skip to content
Open
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
17 changes: 17 additions & 0 deletions buttervolume/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ def exists(self):
# Unexpected error - could indicate system issues
return False

def is_same_as(self, snapshot_path):
"""Check if this snapshot is the same as another snapshot (Can only be used to compare read-only snapshots)"""
# `head -n 2` will return the first two lines and exit immediately instead of waiting for a potentially long processing
bash_cmd = 'btrfs send --no-data -p "$1" "$2" | btrfs receive --dump | head -n 2'
cmd = ["bash", "-c", bash_cmd, "--", snapshot_path, self.path]

lines = run_safe(cmd, timeout=10)

# When there are no changes, it will only output one line
return len(lines.splitlines()) == 1

def is_new(self):
"""Check if this subvolume is new"""
gen_at_creation = self.show()["Gen at creation"]
gen_now = self.show()["Generation"]
return gen_at_creation == gen_now

@btrfs_operation(BtrfsSubvolumeError, "Failed to create snapshot", timeout=120)
def snapshot(self, target, readonly=False):
"""Create a snapshot of this subvolume"""
Expand Down
2 changes: 1 addition & 1 deletion buttervolume/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def runjobs(config=SCHEDULE, test=False, schedule_log=None, timer=TIMER):
continue
log.info("Successfully snapshotted to %s", snap)
schedule_log[action][name] = now
if action.startswith("replicate:"):
if action.startswith("replicate:") or action.startswith("snapshot_sync:"):
if name in ReplicationInProgress:
log.warning(
f"Replication of {name} already in progress, skipping."
Expand Down
Loading