SOLVED reuse snapshot share name for LTO-backup

marum

Dabbler
Joined
Aug 22, 2019
Messages
12
Hi Everybody.

I would like to pull a backup of my dataset to tape. The idea is to take daily snapshots and keep them for 2 weeks. Every weekend the Friday-night snapshot will be written to Tape/LTO.

Unfortunately, I have a pretty basic LTO software that can only do incremental backups of the same share. Therefore, I'm looking for a way to automate weekly sharing of a snapshot, and reusing the share name.

I'm not really sure how this works within ZFS/FreeNas. In my (ongoing) research I found that it might be best to clone the snapshot and share the clone. In that case, I guess I need a cronjob for a shell script with a loop that goes something like:
1) remove last weeks share, and the clone to release the snapshot for automatic snapshot deletion (next week).
2) clone the last snapshot
3) recreate a share for it

Am I over complicating things?

Thank you all!
 

marum

Dabbler
Joined
Aug 22, 2019
Messages
12
Alright,
I have found a solution for this, which seems to work :) It's not perfect, there are no checks to see if the clone is in use or not and so on. But it does the job for me.

I hope that somebody has some use for this.

Cheers

Code:
#!/bin/bash
# This script takes a recursive snapshot of the Servers file system/dataset
# and clones these to the LTO dataset. The idea is to have a weekly alternating
# backup that can be send to LTO. These folders are called weekA for odd weeks
# and weekB for even weeks. I'll refer to these weeks as weekX.

# !!ONLY 1 SUBLEVEL OF DATASETS IS TAKEN INTO ACCOUNT!!

# The process to achieve these clones is as follows:
# 1) Determine if this week is odd (A) or even (B).
# 2) Check if there is already a weekX
#    If there is, remove the clones and the snapshots
# 3) Create a new snapshot for weekX
# 4) Create clones for all snapshots.

# The command to list all snapshots is as follows:
# zfs list -H -t snapshot -r UltraBackup/Backup | grep $week | cut -f 1 | tail -n +2
# explanation:
# zfs list (lists stuff)
#   -H to remove the banner
#   -t snapshot to list snapshots
#   -r to do it for subdatasets
# grep $week limits the output to anything that contains weekA (or weekB)
# cut -f 1 only takes the first whitespace separated field
# tail -n +2 removes the first line, which is the parent dataset

# echo a line first, so that it's clear in the logs...
echo ----------------------------------------

# Set some variables
zpool='UltraBackup'
backupset='Backup'
ltoset='LTO'

# 1) check the week
week=`date +"%V"`
if [ $(($week%2)) -eq 0 ];
then
    week='weekB';
else
    week='weekA';
fi
echo This week it\'s $week;

# 2) Check if weekX exists and remove old
# first remove the clones
while read -r result; do
    echo removing old $week clones: $result;
    zfs destroy -f $result;
done < <(zfs list -H -r $zpool/$ltoset/$week | cut -f 1 | tail -n +2)
# then the snapshots
while read -r result; do
    echo removing old $week snapshot: $result;
    zfs destroy $result;
done < <(zfs list -H -r -t snapshot $zpool/$backupset | grep $week | cut -f 1 )

# 3) create snapshots
echo creating new snapshot $zpool/$backupset@$week
zfs snapshot -r $zpool/$backupset@$week

# 4) create clones
while read -r result; do
    volume=$(basename $result | cut -f1 -d"@");
    echo Creating new clone: $result to $zpool/$ltoset/$week/$volume;
    zfs clone $result $zpool/$ltoset/$week/$volume
done < <(zfs list -H -r -t snapshot $zpool/$backupset | grep $week | cut -f 1 | tail -n +2)
 
Top