ZFS info
Typical backup process
log into your main zfs server
use this one-liner to get the name of the last snapshot in the list, save as a variable, and echo it back:
last_snapshot=$(zfs list -t snapshot | tail -1 | awk '{print $1}') && echo $last_snapshot
form a new variable for your current snapshot
new_snapshot="<name-of-your-pool>@$(date +"%Y-%m-%d_%H-%M")"
for example:
new_snapshot="coldstorage/nas@$(date +"%Y-%m-%d_%H-%M")"
Then take a snapshot and check that it was taken:
zfs snapshot $new_snapshot && zfs list -t snapshot
on secondary machine, ensure that it has the same snapshot:
zfs list -t snapshot
from the primary machine, send it over using the template:
zfs send -v -i <last_snapshot> <current-snapshot> | ssh <secondary-machine> zfs recv <pool/data>
with literals it would look like
zfs send -v -i coldstorage/nas@2022-05-27 coldstorage/nas@2023-06-08_10-00 | ssh storage zfs recv storage
Full example
open in a tmux window in case your ssh session dies or window is closed:
tmux
Then
last_snapshot=$(zfs list -t snapshot | tail -1 | awk '{print $1}')
new_snapshot="coldstorage/nas@$(date +"%Y-%m-%d_%H-%M")"
zfs snapshot $new_snapshot
zfs send -v -i $last_snapshot $new_snapshot | ssh storage zfs recv storage
How to set up ZFS
First install it
sudo apt install -y zfsutils-linux
sudo fdisk -l
lsblk
lsblk -f
define permissions
add permissions using
sudo zfs allow -u <username> receive,create,send,hold,share,snapshot,mount <name-of pool>
For example,
sudo zfs allow -u danaukes receive,create,send,hold,share,snapshot,mount storage
sudo zfs allow -u danaukes receive,create,send,hold,share,snapshot,mount coldstorage
sudo zfs allow -u danaukes receive,create,send,hold,share,snapshot,mount coldstorage/nas
create a pool
sudo zpool create -f storage mirror /dev/sdb /dev/sdc
sudo zpool create -f coldstorage mirror /dev/sda /dev/sde
sudo zpool create -f coldstorage mirror /dev/sda /dev/sdb
Other useful commands related to pools
zpool status
zpool status -v
zpool list
sudo zpool destroy <pool-name>
Some examples
sudo zpool mount coldstorage
sudo zpool unmount coldstorage
sudo zpool online coldstorage
sudo zpool offline coldstorage
sudo zpool detatch coldstarge /dev/sdb1
sudo zpool replace -f coldstorage 11380073923137715223 /dev/sdb
import / export
You can import and export an existing pool if it is not currently loaded on your system.
sudo zpool export coldstorage
sudo zpool import coldstorage -d /dev/
filesystems
https://docs.oracle.com/cd/E19253-01/819-5461/gfkco/index.html
sudo zfs create coldstorage/nas
zfs set readonly=on coldstorage/nas
zfs get mountpoint coldstorage/nas
zfs list
rollback snapshots:
sudo zfs rollback <pool>/<datastore>@<identifier>
sudo zfs rollback coldstorage/nas@test
on colorado
sudo zpool create -f coldstorage mirror /dev/sda /dev/sdb
sudo zfs create coldstorage/nas
sudo zfs set readonly=on coldstorage/nas
sudo zfs rollback coldstorage/nas@test
List all data
zfs list
zfs list -t filesystem
zfs list -t snapshot
snapshots
tmux
zfs snapshot <pool>@<data>/<identifier>
zfs snapshot "storage@$(date +"%Y-%m-%d_%H-%M")"
zfs send -v -i <last_snapshot> <current-snapshot> | ssh <secondary-machine> zfs recv <pool/data>
zfs send -v -i storage@2022-05-27 storage@2023-06-08_10-00 | ssh colorado zfs recv coldstorage/nas
Sending recursive snapshots to another locally
zfs send -R -v storage@test | zfs recv -F coldstorage/nas
Sending recursive snapshots to another datastore remotely
zfs send -R -v storage@test | ssh colorado zfs recv -F coldstorage/nas
debugging
sudo dmesg | grep -i zfs
Highlighted External Links
Managing ZFS File Systems - ZFS Administration Guide
Other External links
-
Main sources:
-
Specific Issues:
- can I zfs send to a zfs pool of a different size? - Google Search
- replication - how to one-way mirror an entire zfs pool to another zfs pool - Unix & Linux Stack Exchange
- How to zfs send to another computer ssh - Google Search
- server - Send ZFS snapshot to remote machine - Ask Ubuntu
- Sending a ZFS Snapshot - Managing ZFS File Systems in Oracle® Solaris 11.2
- zfs requires root privileges zvs send ubuntu - Google Search
- ZFS send/receive over ssh on linux without allowing root login - Super User
- docs.oracle.com/cd/E19253-01/819-5461/gfkco/index.html
- Install and Setup SSH | Dan Aukes
- docs.oracle.com/cd/E19253-01/819-5461/gbiqe/index.html
- ssh pipe zfs send Could not resolve hostname send: Temporary failure in name resolution cannot receive - Google Search
- ssh: Could not resolve hostname server: Name or service not known - Ask Ubuntu
- zfs send | zfs receive as non-root -- Dan Langille\'s Other Diary
- cannot hold: permission denied cannot send \'storage\': permission denied cannot receive: failed to read from stream - Google Search
- Initial Replication Task from On-site Data | TrueNAS Community
- can I change pool size zfs - Google Search
- zfs if I receive a snapshot from a pool of a different size is it resized? - Google Search
- Disabling Password-based SSH | Dan Aukes
- Monitoring the Progress of ZFS Send Streams - Managing ZFS File Systems in Oracle® Solaris 11.2
- ZFS Send Receive Interrupted | TrueNAS Community
- Renaming a ZFS pool -- Prefetch Technologies
- delete zfs pool - Google Search
- google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwj-3Ny1yon_AhWjPEQIHe04CoEQFnoECAwQAQ&url=https%3A%2F%2Fdocs.oracle.com%2Fcd%2FE19253-01%2F819-5461%2Fgaynd%2Findex.html&usg=AOvVaw0EMZouvqzDhl9WiUIZrUng
- How to Mount ZFS Filesystems in Different Directories
- when I zfs send -R does that resize the destination pool? - Google Search
- SOLVED - Manual zfs replication issue | TrueNAS Community
- file-level backup vs zfs - Google Search
- ZFS vs Borg for incremental backup of media files to cold storage? : r/zfs
- ZFS File System (Introduction) - ZFS Administration Guide
- list all datasets zfs - Google Search
- change files in a root pool to a dataset zfs - Google Search
- zfs rename/move root filesystem into child - Server Fault
- PIC18F47Q10 Curiosity Nano Hardware User Guide - PIC18F47Q10-Curiosity-Nano-Hardware-User-Guide-40002103B.pdf
- cannot receive new filesystem stream: permission denied - Google Search
- ZFS send / receive non-root account | by Vignesh A Sathiyanantham | Medium
- Missing Pool:
- https://docs.oracle.com/cd/E19253-01/819-5461/gaynp/index.html
- https://www.reddit.com/r/zfs/comments/uxp4wc/zfs_pool_missing_no_pools_available_disk_is/
- https://www.reddit.com/r/zfs/comments/j62lme/zfs_pool_disappeared_after_reboot/
- https://forums.freebsd.org/threads/zfs-pool-missing-after-crash.65206/
- https://www.google.com/search?client=firefox-b-1-d&q=no+pools+available
- https://discuss.linuxcontainers.org/t/zfs-pool-has-disappeared-visible-with-zpool-import-but-not-in-zpool-list/12928/2
- https://www.osso.nl/blog/zpool-import-no-pools-stale-zdb-labels/
- https://www.truenas.com/community/threads/zpool-status-no-pools-available.18122/