oetiker / znapzend

zfs backup with remote capabilities and mbuffer integration.
www.znapzend.org
GNU General Public License v3.0
608 stars 137 forks source link

Pre-/Post-Commands not working properly #382

Closed umatz closed 3 years ago

umatz commented 5 years ago

Hi,

I was trying to make use of the pre/post-send commands and run into a problem. My configuration looks like this:

dst_a_plan      = 30days=>1day,4weeks=>1week,6months=>1month
dst_a_precmd    = etherwake 00:30:18:a0:11:f9
dst_a_pstcmd    = ssh root@dicky pm-suspend
enabled         = on
mbuffer         = /usr/bin/mbuffer
mbuffer_size    = 1G
post_znap_cmd   = off
pre_znap_cmd    = off
recursive       = off
src             = tank/sysbackup
src_plan        = 7days=>1day
tsformat        = %Y-%m-%d-%H%M%S
zend_delay      = 0

Apart from the issue that the post command in its current form will never return (which I will have to take care of), I run into the problem that the pre- and post-send commands are each run twice. I believe this is an error. After a short look into znapzend/lib/ZnapZend.pm I noticed that both commands are already run in the function(?) refreshBackupPlans and then again in sendRecvCleanup. I am no perl programmer, but I believe that the handling of Pre-/post-send commands should be removed from refreshBackupPlans.

Here is the output from running znapzend with debug logging

[Wed Oct  3 16:48:01 2018] [info] znapzend (PID=19616) starting up ...
[Wed Oct  3 16:48:01 2018] [info] refreshing backup plans...
[Wed Oct  3 16:48:04 2018] [info] **running pre-send-command for root@dicky:tank/sysbackup**
[Wed Oct  3 16:48:04 2018] [info] found a valid backup plan for tank/sysbackup...
[Wed Oct  3 16:48:04 2018] [info] **running post-send-command for root@dicky:tank/sysbackup**
^C[Wed Oct  3 16:48:16 2018] [info] znapzend (PID=19616) initialized -- resuming normal operations.
[Wed Oct  3 16:48:16 2018] [debug] snapshot worker for tank/sysbackup spawned (24125)
[Wed Oct  3 16:48:16 2018] [info] creating snapshot on tank/sysbackup
# zfs snapshot tank/sysbackup@2018-10-03-164816
[Wed Oct  3 16:48:16 2018] [debug] snapshot worker for tank/sysbackup done (24125)
[Wed Oct  3 16:48:16 2018] [debug] send/receive worker for tank/sysbackup spawned (24127)
[Wed Oct  3 16:48:16 2018] [info] starting work on backupSet tank/sysbackup
[Wed Oct  3 16:48:16 2018] [info] **running pre-send-command for root@dicky:tank/sysbackup**
[Wed Oct  3 16:48:16 2018] [debug] sending snapshots from tank/sysbackup to root@dicky:tank/sysbackup
# zfs list -H -o name -t snapshot -s creation -d 1 tank/sysbackup
# ssh -o batchMode=yes -o ConnectTimeout=30 root@dicky zfs list -H -o name -t snapshot -s creation -d 1 tank/sysbackup
# ssh -o batchMode=yes -o ConnectTimeout=30 root@dicky zfs list -H -o name -t snapshot -s creation -d 1 tank/sysbackup
[Wed Oct  3 16:48:25 2018] [debug] cleaning up snapshots on root@dicky:tank/sysbackup
# ssh -o batchMode=yes -o ConnectTimeout=30 root@dicky zfs destroy tank/sysbackup@2018-10-03-162751
[Wed Oct  3 16:48:25 2018] [info] **running post-send-command for root@dicky:tank/sysbackup**
^C[Wed Oct  3 16:48:31 2018] [debug] SIGINT received.
[Wed Oct  3 16:48:31 2018] [info] terminating znapzend (PID=19616) ...
# zfs list -H -o name -t snapshot -s creation -d 1 tank/sysbackup
[Wed Oct  3 16:48:31 2018] [debug] cleaning up snapshots on tank/sysbackup
# zfs destroy tank/sysbackup@2018-10-03-162751
[Wed Oct  3 16:48:31 2018] [info] done with backupset tank/sysbackup in 15 seconds
[Wed Oct  3 16:48:32 2018] [info] znapzend (PID=19616) terminated.
Beneter commented 5 years ago

After reviewing the sourcecode I can confirm, that refreshBackupPlans is executing the pre and post commands. But as far as I can see this is only being done when starting the daemon (probably for immediate feedback if something fails). When the daemon is running refreshBackupPlanswill not be invoked until restart.

oetiker commented 5 years ago

or when it gets a HUP signal ... this is intentional.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.