mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-04-11 22:40:01 +03:00
also support non gnu xargs
This commit is contained in:
parent
f4ebd8ac38
commit
101c8d5525
@ -132,9 +132,11 @@ def zfs_get_selected_filesystems(ssh_to, backup_name):
|
||||
|
||||
"""destroy list of filesystems or snapshots"""
|
||||
def zfs_destroy(ssh_to, filesystems):
|
||||
|
||||
debug("Destroying on {0}:\n{1}".format(ssh_to, "\n".join(filesystems)))
|
||||
#zfs can only destroy one filesystem at once so we use xargs and stdin
|
||||
run(ssh_to=ssh_to, test=args.test, input="\n".join(filesystems)+"\n", cmd=
|
||||
[ "xargs", "-d", "\\n", "-n", "1", "zfs", "destroy", "-d" ]
|
||||
run(ssh_to=ssh_to, test=args.test, input="\0".join(filesystems), cmd=
|
||||
[ "xargs", "-0", "-n", "1", "zfs", "destroy", "-d" ]
|
||||
)
|
||||
|
||||
|
||||
@ -345,18 +347,6 @@ for source_filesystem in source_filesystems:
|
||||
latest_target_snapshot=send_snapshot
|
||||
|
||||
|
||||
#cleanup old target snapshots
|
||||
target_destroys=[]
|
||||
for target_filesystem in target_snapshots:
|
||||
destroy_count=len(target_snapshots[target_filesystem])-args.keep_target
|
||||
if destroy_count>0:
|
||||
for snapshot in target_snapshots[target_filesystem][0:destroy_count-1]:
|
||||
target_destroys.append(target_filesystem+"@"+snapshot)
|
||||
|
||||
if target_destroys:
|
||||
verbose("Destroying old snapshots on target")
|
||||
zfs_destroy(ssh_to=args.ssh_target, filesystems=target_destroys)
|
||||
|
||||
#cleanup old source snapshots
|
||||
source_destroys=[]
|
||||
for source_filesystem in source_snapshots:
|
||||
@ -369,5 +359,19 @@ if source_destroys:
|
||||
verbose("Destroying old snapshots on source")
|
||||
zfs_destroy(ssh_to=args.ssh_source, filesystems=source_destroys)
|
||||
|
||||
|
||||
#cleanup old target snapshots
|
||||
target_destroys=[]
|
||||
for target_filesystem in target_snapshots:
|
||||
destroy_count=len(target_snapshots[target_filesystem])-args.keep_target
|
||||
if destroy_count>0:
|
||||
for snapshot in target_snapshots[target_filesystem][0:destroy_count-1]:
|
||||
target_destroys.append(target_filesystem+"@"+snapshot)
|
||||
|
||||
if target_destroys:
|
||||
verbose("Destroying old snapshots on target")
|
||||
zfs_destroy(ssh_to=args.ssh_target, filesystems=target_destroys)
|
||||
|
||||
|
||||
verbose("All done")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user