Skip to content

Commit

Permalink
added zfs notes
Browse files Browse the repository at this point in the history
  • Loading branch information
aceat64 committed Aug 21, 2023
1 parent 33e3ae2 commit faf7694
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 104 deletions.
1 change: 0 additions & 1 deletion content/guides/http-status-codes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
status: new
description: A comical explanation of various HTTP status codes.
---

Expand Down
104 changes: 104 additions & 0 deletions content/guides/zfs-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
status: new
description: Various notes about my usage of ZFS/OpenZFS.
---

# ZFS Notes

In this document, replace `worldsgrave` with the name of your zpool.

## Recommended settings

### Compression

Use `lz4` compression, it's fast and efficient.

```shell
zfs set compression=lz4 worldsgrave
```

### Access Time

Turn off `atime`, it's useless.

```shell
zfs set atime=off worldsgrave
```

### De-Duplication

!!! warning "De-Duplication"
**NEVER** use de-dupe, it's a massive performance hit.

## Scheduled Scrubing

Create the following files:

??? example "/etc/systemd/system/zfs-scrub@.service"

``` desktop
[Unit]
Description=zpool scrub on %i

[Service]
Nice=19
IOSchedulingClass=idle
KillSignal=SIGINT
ExecStart=/usr/sbin/zpool scrub %i

[Install]
WantedBy=multi-user.target
```

??? example "/etc/systemd/system/zfs-scrub@.timer"

``` desktop
[Unit]
Description=Monthly zpool scrub on %i

[Timer]
OnCalendar=monthly
AccuracySec=1h
Persistent=true

[Install]
WantedBy=multi-user.target
```

Enable and start the new service:

```shell
systemctl daemon-reload
systemctl enable zfs-scrub@worldsgrave.timer
```

## Scheduled Snapshots

Install zrepl, see [zrepl.yaml](zrepl.yaml) for reference.

## Useful Commands

### List datasets

```shell
zfs list -o type,name,available,used,logicalused,usedbysnapshots,compressratio,mountpoint
```

### List snapshots

```shell
zfs list -t snapshot
```

### Recordsize

```shell
zfs get recordsize -t filesystem
```

### Aliases

``` shell
alias zls="zfs list -o type,name,available,used,logicalused,usedbysnapshots,compressratio,mountpoint"+
alias zsl="zfs list -t snapshot"
```
99 changes: 99 additions & 0 deletions content/guides/zfs-notes/zrepl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
global:
logging:
# use syslog instead of stdout because it makes journald happy
- type: syslog
format: human
level: warn
monitoring:
# Maker prometheus metrics available for scraping
- type: prometheus
listen: ":9811"
listen_freebind: true # Enabled, so that zrepl will listen on all IPs, even if they are bound after zrepl starts

# see /usr/share/doc/zrepl/examples
# or https://zrepl.github.io/configuration/overview.html
# or https://zrepl.github.io/quickstart/backup_to_external_disk.html

jobs:
# snapshot creation + pruning for worldsgrave
- name: worldsgrave_snapshots
type: snap
filesystems: {
"worldsgrave<": true,
"worldsgrave/zrepl<": false, # Don't snapshot snapshots from rpool, that would be super dumb
"worldsgrave/k8s<": false, # Dont' snapshot k8s PVs, the ZFS operator will do that as needed
"worldsgrave/timemachine<": false, # Don't snapshot timemachine backups, that would also be dumb
}
# create snapshots with prefix `zrepl_` every 15 minutes
snapshotting:
type: periodic
interval: 15m
prefix: zrepl_
pruning:
keep:
# Fade-out scheme for snapshots starting with `zrepl_`
# - Keep all created in the last hour
# - Keep 24 each 1 hour apart
# - Keep 14 each 1 day apart
# - All older snapshots will be destroyed unless other keep rules apply to them
- type: grid
grid: 1x1h(keep=all) | 24x1h | 14x1d
regex: "^zrepl_.*"
# Keep all snapshots that don't have the `zrepl_` prefix
# This protects manually created snapshots from being pruned by zrepl
- type: regex
negate: true
regex: "^zrepl_.*"

# Provide a destination on worldsgrave for snapshots from rpool
- name: "worldsgrave_sink"
type: sink
root_fs: "worldsgrave/zrepl"
serve:
type: local
listener_name: localsink

# Backup root snapshots to worldsgrave
- name: "backup_root"
type: push
connect:
type: local
listener_name: localsink
client_identity: backup_root
filesystems: {
"rpool<": true,
"rpool/k3s_agent<": false, # Don't snapshot the k3s agent zvol, it's not needed
"rpool/k8s<": false, # Dont' snapshot k8s PVs, the ZFS operator will do that as needed
}
# Create snapshots with prefix `zrepl_` every 30 minutes
snapshotting:
type: periodic
interval: 30m
prefix: zrepl_
pruning:
keep_sender:
# Keep any snapshots on rpool that haven't been replicated to worldsgrave/zrepl yet
- type: not_replicated
# Fade-out scheme for snapshots starting with `zrepl_` on rpool
# - Keep all created in the last hour
# - Keep 24 each 1 hour apart
# - All older snapshots will be destroyed unless other keep rules apply to them
- type: grid
grid: 1x1h(keep=all) | 24x1h
regex: "zrepl_.*"
# Keep all snapshots that don't have the `zrepl_` prefix
- type: regex
negate: true
regex: "^zrepl_.*"
keep_receiver:
# Fade-out scheme for snapshots starting with `zrepl_` on worldsgrave/zrepl
# - Keep 14 each 1 day apart
# - All older snapshots will be destroyed unless other keep rules apply to them
- type: grid
grid: 14x1d
regex: "zrepl_.*"
# Keep all snapshots that don't have the `zrepl_` prefix
# This protects manually created snapshots from being pruned by zrepl
- type: regex
negate: true
regex: "^zrepl_.*"
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nav:
- guides/rpi-k8s-talos-terraform.md
- guides/mkdocs-material-insider-github-pages-action.md
- guides/http-status-codes.md
- guides/zfs-notes.md
- Smart Home:
- smart-home/architecture.md
- smart-home/garage-door.md
Expand Down

0 comments on commit faf7694

Please sign in to comment.