Script to Delete Snapshots on Backup/Replication Server

linchesterBR

Cadet
Joined
Feb 13, 2019
Messages
6
I would like to know if is possible to create a script to delete snapshots on backup/replication server side.

We have the option "Delete Stale Snapshots on Remote System", but this is not very secure because if we accidentally (or not) delete these snapshots on primary server, they also will be deleted on remote server.

Therefore, we could let this option unchecked and control retention by script. But I can't find where snapshots are stored on the remote server and I even don't know if we can simply delete them.

Any help is welcome.

Thanks in advance.
 

Meyers

Patron
Joined
Nov 16, 2016
Messages
211
They're just regular snapshots on the backup. You can browse for them in the GUI or use zfs list -t snapshot to see them.

You should be able to delete old snapshots on the backup provided they are already deleted on the primary. You'd have to test this of course.

That said, this is probably a lot of work for a very unlikely event.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
I think the key here is "stale" snapshots...

The snapshots that have expired and hence will be automatically deleted on the master are also deleted on the replica, nothing else. Unless you expire the snapshot somehow on the master, replicate it and then delete it, the scenario you're trying to cover doesn't exist.
 

linchesterBR

Cadet
Joined
Feb 13, 2019
Messages
6
What I'm looking for is a way to control the snapshot retention on remote backup system without depends on "Delete Stale" option. I think a solution is a command like this:

# zfs list -t snapshot -o name -S creation | grep primary_server | tail -n +11 | xargs -n 1 zfs destroy -vr

* In this example it will list the snapshots ordering by creation date, filter by primary_server, select the lines from the 11th and pass them like arguments for the destroy command. So, I could cron this command on remote system to keep on it just the newest 10 snapshots of a primary server.
 
Top