From 3b9b96243b44583a0da36ef6dd2f14358130d52a Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Wed, 2 Oct 2019 19:39:31 +0200 Subject: [PATCH] dont destroy stale snapshots if we're using --ignore-replicated --- README.md | 4 ++-- zfs_autobackup | 42 +++++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index d88a4cf..b2a5b18 100644 --- a/README.md +++ b/README.md @@ -302,7 +302,7 @@ Preparing the backup server Extra options needed for proxmox with HA: * --no-holds: To allow proxmox to destroy our snapshots if a VM migrates to another node. -* --ignore-replicated: To ignore the replicated filesystems of proxmox on the receiving nodes. (only backup from the node where the VM is active) +* --ignore-replicated: To ignore the replicated filesystems of proxmox on the receiving proxmox nodes. (e.g: only backup from the node where the VM is active) I use the following backup script on the backup server: @@ -310,7 +310,7 @@ I use the following backup script on the backup server: for H in h4 h5 h6; do echo "################################### DATA $H" #backup data filesystems to a common place - ./zfs_autobackup --ssh-source root@$H data_smartos03 zones/backup/zfsbackups/pxe1_data --clear-refreservation --clear-mountpoint --ignore-transfer-errors --strip-path 2 --verbose --resume --ignore-replicated --no-holds $@ + ./zfs_autobackup --ssh-source root@$H data_smartos03 zones/backup/zfsbackups/pxe1_data --clear-refreservation --clear-mountpoint --ignore-transfer-errors --strip-path 2 --verbose --resume --ignore-replicated --no-holds $@ zabbix-job-status backup_$H""_data_smartos03 daily $? >/dev/null 2>/dev/null echo "################################### RPOOL $H" diff --git a/zfs_autobackup b/zfs_autobackup index 61397ed..7b26ded 100755 --- a/zfs_autobackup +++ b/zfs_autobackup @@ -406,7 +406,7 @@ these are filesystems that are not in the list in target_filesystems. this happens when filesystems are destroyed or unselected on the source. """ -def get_stale_backupped_filesystems(ssh_to, backup_name, target_path, target_filesystems, existing_target_filesystems): +def get_stale_backupped_filesystems(backup_name, target_path, target_filesystems, existing_target_filesystems): @@ -714,28 +714,32 @@ def zfs_autobackup(): #we only do cleanups after everything is complete, to keep everything consistent (same snapshots everywhere) - #find stale backups on target that have become obsolete - # verbose("Getting stale filesystems and snapshots from {0}".format(args.ssh_target)) - stale_target_filesystems=get_stale_backupped_filesystems(ssh_to=args.ssh_target, backup_name=args.backup_name, target_path=args.target_path, target_filesystems=target_filesystems, existing_target_filesystems=existing_target_filesystems) - debug("Stale target filesystems: {0}".format("\n".join(stale_target_filesystems))) + if not args.ignore_replicated: + #find stale backups on target that have become obsolete - stale_target_snapshots=zfs_get_snapshots(args.ssh_target, stale_target_filesystems, args.backup_name) - debug("Stale target snapshots: " + str(pprint.pformat(stale_target_snapshots))) - target_obsolete_snapshots.update(stale_target_snapshots) + stale_target_filesystems=get_stale_backupped_filesystems(backup_name=args.backup_name, target_path=args.target_path, target_filesystems=target_filesystems, existing_target_filesystems=existing_target_filesystems) + debug("Stale target filesystems: {0}".format("\n".join(stale_target_filesystems))) - #determine stale filesystems that have no snapshots left (the can be destroyed) - #TODO: prevent destroying filesystems that have underlying filesystems that are still active. - stale_target_destroys=[] - for stale_target_filesystem in stale_target_filesystems: - if stale_target_filesystem not in stale_target_snapshots: - stale_target_destroys.append(stale_target_filesystem) + stale_target_snapshots=zfs_get_snapshots(args.ssh_target, stale_target_filesystems, args.backup_name) + debug("Stale target snapshots: " + str(pprint.pformat(stale_target_snapshots))) + target_obsolete_snapshots.update(stale_target_snapshots) - if stale_target_destroys: - # if args.destroy_stale: - # verbose("Destroying stale filesystems on target {0}:\n{1}".format(args.ssh_target, "\n".join(stale_target_destroys))) - # zfs_destroy(ssh_to=args.ssh_target, filesystems=stale_target_destroys, recursive=True) - # else: + #determine stale filesystems that have no snapshots left (the can be destroyed) + stale_target_destroys=[] + for stale_target_filesystem in stale_target_filesystems: + if stale_target_filesystem not in stale_target_snapshots: + stale_target_destroys.append(stale_target_filesystem) + + if stale_target_destroys: + #NOTE: dont destroy automaticly..not safe enough. + # if args.destroy_stale: + # verbose("Destroying stale filesystems on target {0}:\n{1}".format(args.ssh_target, "\n".join(stale_target_destroys))) + # zfs_destroy(ssh_to=args.ssh_target, filesystems=stale_target_destroys, recursive=True) + # else: verbose("Stale filesystems on {0}:\n{1}".format(args.ssh_target, "\n".join(stale_target_destroys))) + else: + verbose("NOTE: Cant determine stale target filesystems while using ignore_replicated.") + #now actually destroy the old snapshots