Pull replication and deletion of snapshots

nag4u

Cadet
Joined
Sep 15, 2022
Messages
3
I have set up a pull replication task from truenas1 to truenas2. I need to set up a task to delete old snapshots automatically. I could do this through a cron job, but I was really hoping that there would just be an option I could enable on the truenas2 side that would automatically take care of old snapshots after replication.

I was looking at the documentation for replication, and a lot of the fields that I thought I wanted to use turns out I probably don't want to use, they just have unfortunate titles or definitions.

Snapshot Retention Policy. I would immediately go to this on truenas2 to manage the lifetime of the snapshots on truenas2. Since truenas2 does not have a snapshot task for managing said snapshots, the name of this option tells me that this is what I want for automated cleanup of snapshots. The documentation says otherwise. It says that this is only triggered if truenas2 has no snapshot data in common with truenas1 snapshots. Useful in some key scenarios, but not what I'm looking for.

The next closest item would be Synchronize Destination Snapshots With Source. This is actually something I really do not want to do. If truenas1 is breached and someone runs a delete against all of the snapshots, then truenas2 would, presumably, delete all of its snapshots. This was one of the problems with push replication in previous versions of FreeNAS. The TrueNAS documentation says that it's for using encryption when replicating data...? Which I think might be a bug in the docs.

So in the end, I am at a loss. I did try to use Snapshot Retention Policy to do what I want. Can confirm, it does not do what I want. Regardless of whether I set to Custom or Same As Source, it will not trigger. I let the system go for a while, and on truenas2 I ended up with over 2,000 snapshots per dataset that was being replicated. On truenas1, it's a consistent 334, which is what I expect.

Is there a way to manage snapshot longevity on the destination side of a pull replication, or am I stuck doing this through a cron job?
 

florihupf

Cadet
Joined
Jan 13, 2022
Messages
7
I am just here to say that I have 100% the same issue. Also not sure what all the options are really doing. They are described / named in a way that doesn’t make it perfectly clear what is happening.

Any pointers much appreciated.
 

nag4u

Cadet
Joined
Sep 15, 2022
Messages
3
The best solution would be to have something in the interface that could manage snapshots, but in years past, I would use Sanoid for this. If there's not a way to do it in the interface, maybe Sanoid can help you. I'd like to avoid using it again, because I want to do things the TrueNAS way and not install things on the base OS. But desperate times, desperate measures, and such.

 

lopr

Explorer
Joined
Mar 19, 2015
Messages
71
I am doing it via cron and I wrote a very ugly bash script that whips out a monstrosity of a regex to delete any snapshots older than X days if you are interested
 

nag4u

Cadet
Joined
Sep 15, 2022
Messages
3
I am doing it via cron and I wrote a very ugly bash script that whips out a monstrosity of a regex to delete any snapshots older than X days if you are interested
Hecks yeah! Bring it on. This would be way better than trying to crowbar Sanoid back on to TrueNAS. I've done it before, I can do it again, I'd rather not have to.
 

lopr

Explorer
Joined
Mar 19, 2015
Messages
71

SMnasMAN

Contributor
Joined
Dec 2, 2018
Messages
177
Im in the same boat, Im running TrueNAS 12.0 u8.1 , it is doing PULL replication from my main/master Freenas 11.3 box. This part is working great. However of my 5x PULL replication tasks, only 2x properly delete snapshots as defined my settings. There is clearly a bug here as my tasks have the exact same settings (ive even compared them at the CLI level via midclt call replication.query | jq ... just to be 100% sure its not a gui issue).

The best correlation ive been able to find, is that any Replication tasks that have MORE THAN 1x source dataset, will not delete snapshots properly. (no matter what settings you run, snapshots will just pile up, and based on the logs i dont even see an attempt at auto deleting snaps).

my 3x Pull replication tasks that only have 1x source (to pull from), do delete snapshots according to what i set in "Snapshot Retention Policy = 4 weeks" My snaps are named properly, ie in the format: "auto-20220530.0100-4w"

I agree the documentation is very poor, as are the names/descriptions of the options in the Replication task setup page (in fact some are quite dangerous! ive unintentionally wiped 9TB of remote backup data via the "Synchronize Destination Snapshots With Source" check box.)

images of what im referring to.

1667330149189.png
 

zatarc

Cadet
Joined
Mar 7, 2022
Messages
4
Same problem here. truenas2 pulls from truenas1 and ignores all snapshot lifetime settings:

1667550489479.png


But truenas2 does not delete snapshots older than 1 month...

So is this a bug or am I using it wrong?
 

zatarc

Cadet
Joined
Mar 7, 2022
Messages
4
For those who are interested - I wrote a small bash script as a workaround:

Code:
#!/bin/bash

RETENTION_TIME="1 month"
SNAPSHOT_FILTER="data/backup"

simulate=false
while [[ $# -gt 0 ]]; do
  case $1 in
    -s|--simulate)
      simulate=true
      shift
      ;;
  esac
done

timestamp=$(date -d "${RETENTION_TIME} ago" +%s)

for snapshot in $(zfs list -H -t snapshot -o name | grep ${SNAPSHOT_FILTER}); do
  snapshot_timestamp=$(zfs get creation -o value -Hp -t snapshot $snapshot)
  if [ ${snapshot_timestamp} -lt ${timestamp} ]; then
    if [ "${simulate}" = true ]; then
      echo [simulate] zfs destroy snapshot ${snapshot}
    else
      echo zfs destroy ${snapshot}
      zfs destroy ${snapshot}
    fi
  fi
done


Pass -s as argument to simulate a run. Without -s it will actually delete snapshots older than RETENTION_TIME. With SNAPSHOT_FILTER it is possible to filter which snapshots should be considered.
 
Top