Skip to content

Commit

Permalink
Delete btrfs snapshots in 20-subvol batches
Browse files Browse the repository at this point in the history
To avoid creating too long shell commands.
  • Loading branch information
cvaroqui committed Mar 20, 2023
1 parent 3ccc9fe commit e05a854
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion opensvc/drivers/resource/sync/btrfs/__init__.py
Expand Up @@ -9,6 +9,7 @@
import core.exceptions as ex
from .. import Sync, notify
from env import Env
from utilities.chunker import chunker
from utilities.converters import print_duration
from utilities.string import bdecode
from utilities.files import makedirs, protected_dir
Expand Down Expand Up @@ -155,8 +156,12 @@ def pre_action(self, action):
continue

r.get_src_info()
r.remove_src_snap_next()

for i, r in enumerate(resources):
tosends = []


for subvol in r.subvols():
src = r.src_btrfs.rootdir + "/" + subvol["path"]
dst = r.src_snap_next(subvol)
Expand Down Expand Up @@ -218,7 +223,7 @@ def remote_subvols(self, node):
def recreate_snaps(self, snaps):
self.make_src_workdirs()
self.init_src_btrfs()
self.src_btrfs.subvol_delete([snap[1] for snap in snaps])
self.src_btrfs.subvol_delete([snap[1] for snap in snaps if os.path.exists(snap[1])])
try:
self.src_btrfs.snapshots(snaps, readonly=True)
except utilities.subsystems.btrfs.ExistError:
Expand Down Expand Up @@ -400,6 +405,18 @@ def remove_dst_snap_last(self, node):
return []
return [subprocess.list2cmdline(cmd)]

def remove_src_snap_next(self):
o = self.get_btrfs()
p = self.src_next_dir()
subvols = o.get_subvols_in_path(p)
cmds = []
for bunch in chunker(subvols, 20):
cmd = o.subvol_delete_cmd(bunch) or []
if not cmd:
continue
cmds = [subprocess.list2cmdline(cmd)]
self.do_cmds(cmds)

def remove_src_snap_last(self):
o = self.get_btrfs()
p = self.src_last_dir()
Expand Down

0 comments on commit e05a854

Please sign in to comment.