ZFS Toolbox

 

Auf dieser Seite findest du nützliche Scripte, Tools und Tipps rund um ZFS.

ZFS holds

Alle Snapshots mit gestzten holds in einem ZFS-Pool ermitteln:

zfs get -Ht snapshot userrefs | grep -v $'\t'0 | cut -d $'\t' -f 1 | tr '\n' '\0' | xargs -0 zfs holds | grep <POOL_NAME> 

Bei allen Snapshots im ZFS-Pool die Holds entfernen:

for i in $(zfs get -Ht snapshot userrefs | grep -v $'\t'0 | cut -d $'\t' -f 1 | tr '\n' '\0' 
         | xargs -0 zfs holds | grep <POOL_NAME> | awk '{ print $1"|"$2 }'); do 
    zfs release ${i#*|} ${i%|*}; 
done

 

 

Clone (encrypted) Datasets inkl. aller Snaphots

Mit zfs send un zfs receive können (verschlüsselte) Datasets inklusive aller Snapshots per SSH über das Netzwerk übertragen werden:

Hinweis: Im folgenden Script wird davon ausgegangen, dass man sich auf dem Ziel-Rechner befindet der die geklonten Daten empfangen soll. 
Die Umgebungsvariablen am Anfang des Scripts müssen entsprechend angepasst werden.

 

SRC_HOST=<SRC_HOST>
SRC_POOL=<SRC_POOL>
SRC_DATASET=<SRC_DATASET>
DST_POOL=$SRC_POOL

# zpool auf dem Zielsystem anlegen, z.B. als single disk:
zpool create -o ashift=12  $DST_PPOL <DEV> 

# zpool Parameter abgleichen:
diff <(ssh $SRC_HOST "zpool get all $SRC_POOL" | awk '{ printf "%-20s %-40s %s\n",  $1, $2, $3 }') \
      <(zpool get all $DST_POOL| awk '{ printf "%-20s %-40s %s\n",  $1, $2, $3 }')

# Snapshot für die Migration auf dem Quellsystem erstellen:
ssh $SRC_HOST zfs snapshot -r $SRC_POOL/$SRC_DATASET@migration

# Snapshot per SSH auf das lokale System übertragen:
# Send-Parameter:
#   -R  Generate a replication stream package, which will replicate the specified file system, and all 
#       descendent file systems, up to the named snapshot. When received, all properties, snapshots, 
#       descendent file systems, and clones are preserved.
#   -w For encrypted datasets, send data exactly as it exists on disk. This allows backups to be taken 
#       even if encryption keys are not currently loaded. The backup may then be received on an untrusted 
#       machine since that machine will not have the encryption keys to read the protected data or alter 
#       it without being detected. Upon being received, the dataset will have the same encryption keys 
#       as it did on the send side, although the keylocation property will be defaulted to prompt if not 
#       otherwise provided. For unencrypted datasets, this flag will be equivalent to -Lec. Note that if 
#       you do not use this flag for sending encrypted datasets, data will be sent unencrypted and may 
#       be re-encrypted with a different encryption key on the receiving system, which will disable the 
#       ability to do a raw send to that system for incrementals.
#   -h Generate a stream package that includes any snapshot holds (created with the zfs hold command), 
#       and indicating to zfs receive that the holds be applied to the dataset on the receiving system.
# Receive-Parameter:
#   -d Discard the first element of the sent snapshot's file system name, using the remaining elements to 
#       determine the name of the target file system for the new snapshot 
#       
ssh $SRC_HOST "zfs send -Rwh $SRC_POOL/$SRC_DATASET@migration" | zfs receive -d $DST_POOL

# Holds abgleichen
diff <(ssh $SRC_HOST "zfs get -Ht snapshot userrefs | grep -v $'\t'0 | \
     cut -d $'\t' -f 1 | tr '\n' '\0' | xargs -0 zfs holds" | \
     grep $SRC_POOL | awk '{ printf "%-30s %s", $2 ,$1 }') \
     <(zfs get -Ht snapshot userrefs | grep -v $'\t'0 | cut -d $'\t' -f 1 | tr '\n' '\0' | \
     xargs -0 zfs holds |  grep $DST_POOL | awk '{ printf "%-30s %s", $2 ,$1 }')

# Parameter der Datasets abgleichen Dataset
diff <(ssh $SRC_HOST "zfs get all $SRC_POOL/$SRC_DATASET") \
     <(zfs get all $DST_POOL/$SRC_DATASET)

# Migrationssnapshot entfernen
zfs destroy -r $DST_POOL/$SRC_DATASET@migration
ssh $SRC_HOST "zfs destroy -r $SRC_POOL/$SRC_DATASET@migration"

Ubuntu Snapshot Cleanup

 

 

# Set Pattern used to select snapshots to be deleted
PATTERN=2023-09

# ausgewählte zsysctl system snapshots löschen
for i in $(zsysctl show | grep -e "- rpool/USERDATA/root_.*@autozsys.*$PATTERN" | awk ' { print $2 } '); do 
    i=${i#*@autozsys_}
    zsysctl state remove $i -s;
    zsysctl state remove $i -u root
    zsysctl state remove $i -u stephan
done

# ausgewählte zsysctl user snapshots löschen
for i in $(zsysctl show | grep -e "- rpool/USERDATA/stephan_.*@autozsys.*$PATTERN" | awk ' { print $2 } '); do 
    i=${i#*@autozsys_}
    zsysctl state remove $i -u stephan
done

# ausgewählte andere zfs snapshots löschen
TODO

 

 

Quellen:

[01] https://openzfs.github.io/openzfs-docs/man/master/8/zfs-recv.8.html  
[02] https://openzfs.github.io/openzfs-docs/man/master/8/zfs-send.8.html 
[03]

Kommentare

PostadresseE-MailadresseFestnetzMobiltelefonSMS/SignalThreemaTwitter DirektnachrichtFAXWeb Page