Last active
June 21, 2023 17:29
-
-
Save brianmed/472f8e6a7faf862b3b4541bca666358d to your computer and use it in GitHub Desktop.
ZFS Initial Setup on Devuan + Multiple Snapshot Types + Compression + Deduplication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/usr/bin/rsync -az --quiet --partial --delete-after \ | |
--exclude-from=rsync_remote_excludes \ | |
. \ | |
user@server:/mnt/backups/hostname | |
# Use date --date='@##########' on Linux.. below works with macOS connecting to Linux Devuan | |
# So all timestamps are the same epoch per script invocation | |
NOW=$(date '+%s') | |
# Extract for timebox logic below | |
MONTHLY=$(date -r "$NOW" '+%d') | |
WEEKLY=$(date -r "$NOW" '+%w') | |
DAILY=$(date -r "$NOW" '+%T') | |
# Timeboxed for cordination with cron.. hopefully once a day | |
if [[ "$DAILY" > "00:00:00" && "$DAILY" < "00:15:00" ]]; then | |
if [[ $MONTHLY -eq 1 ]]; then | |
# First of the month | |
ssh user@server nohup sudo zfs snapshot backups/rsync@$(date -r "$NOW" '+%s_%A_%H_%M_00_Monthly') | |
fi | |
if [[ $WEEKLY -eq 0 ]]; then | |
# Start of the week | |
ssh user@server nohup sudo zfs snapshot backups/rsync@$(date -r "$NOW" '+%s_%A_%H_%M_01_Weekly') | |
fi | |
# Every day | |
ssh user@server nohup sudo zfs snapshot backups/rsync@$(date -r "$NOW" '+%s_%A_%H_%M_02_Daily') | |
fi | |
# Always create an hourly snapshot | |
ssh user@server nohup sudo zfs snapshot backups/rsync@$(date -r "$NOW" '+%s_%A_%H_%M_03_Hourly') | |
# Prune old snapshots | |
ssh user@server nohup zsh -c \''SNAPSHOTS=$(/sbin/zfs list -H -t snapshot | grep "Weekly" | sed -e "s/[[:space:]].*//") && test $(wc -l <<< $SNAPSHOTS) -gt 8 && for i in $(echo $SNAPSHOTS | head --lines=-8); do sudo /sbin/zfs destroy "$i"; done'\' | |
ssh user@server nohup zsh -c \''SNAPSHOTS=$(/sbin/zfs list -H -t snapshot | grep "Monthly" | sed -e "s/[[:space:]].*//") && test $(wc -l <<< $SNAPSHOTS) -gt 2 && for i in $(echo $SNAPSHOTS | head --lines=-2); do sudo /sbin/zfs destroy "$i"; done'\' | |
ssh user@server nohup zsh -c \''SNAPSHOTS=$(/sbin/zfs list -H -t snapshot | grep "Daily" | sed -e "s/[[:space:]].*//") && test $(wc -l <<< $SNAPSHOTS) -gt 14 && for i in $(echo $SNAPSHOTS | head --lines=-14); do sudo /sbin/zfs destroy "$i"; done'\' | |
ssh user@server nohup zsh -c \''SNAPSHOTS=$(/sbin/zfs list -H -t snapshot | grep "Hourly" | sed -e "s/[[:space:]].*//") && test $(wc -l <<< $SNAPSHOTS) -gt 24 && for i in $(echo $SNAPSHOTS | head --lines=-24); do sudo /sbin/zfs destroy "$i"; done'\' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[bpm@bmedley] c:~>/sbin/zfs list -H -t snapshot | |
backups/rsync@1627772883_Saturday_18_08_03_Hourly 348M - 68.6G - | |
backups/rsync@1627783690_Saturday_21_08_03_Hourly 219M - 68.6G - | |
backups/rsync@1627794475_Sunday_00_07_00_Monthly 0B - 68.6G - | |
backups/rsync@1627794475_Sunday_00_07_01_Weekly 0B - 68.6G - | |
backups/rsync@1627794475_Sunday_00_07_02_Daily 0B - 68.6G - | |
backups/rsync@1627794475_Sunday_00_07_03_Hourly 0B - 68.6G - | |
backups/rsync@1627805278_Sunday_03_07_03_Hourly 186M - 68.6G - | |
backups/rsync@1627816071_Sunday_06_07_03_Hourly 187M - 68.6G - | |
backups/rsync@1627826880_Sunday_09_08_03_Hourly 217M - 68.6G - | |
backups/rsync@1627837690_Sunday_12_08_03_Hourly 226M - 68.6G - | |
backups/rsync@1627848483_Sunday_15_08_03_Hourly 129M - 68.6G - | |
backups/rsync@1627859273_Sunday_18_07_03_Hourly 134M - 68.6G - | |
backups/rsync@1627870090_Sunday_21_08_03_Hourly 191M - 68.5G - | |
backups/rsync@1627880871_Monday_00_07_02_Daily 0B - 68.5G - | |
backups/rsync@1627880871_Monday_00_07_03_Hourly 0B - 68.5G - | |
backups/rsync@1627891676_Monday_03_07_03_Hourly 158M - 68.5G - | |
backups/rsync@1627902479_Monday_06_07_03_Hourly 142M - 68.5G - | |
backups/rsync@1627913279_Monday_09_07_03_Hourly 146M - 68.5G - | |
backups/rsync@1627924086_Monday_12_08_03_Hourly 172M - 68.5G - | |
backups/rsync@1627934871_Monday_15_07_03_Hourly 165M - 68.5G - | |
backups/rsync@1627945687_Monday_18_08_03_Hourly 226M - 68.5G - | |
backups/rsync@1627956504_Monday_21_08_03_Hourly 261M - 68.7G - | |
backups/rsync@1627967296_Tuesday_00_08_02_Daily 0B - 68.8G - | |
backups/rsync@1627967296_Tuesday_00_08_03_Hourly 0B - 68.8G - | |
backups/rsync@1627978089_Tuesday_03_08_03_Hourly 204M - 68.8G - | |
backups/rsync@1627988874_Tuesday_06_07_03_Hourly 199M - 68.8G - | |
backups/rsync@1627999687_Tuesday_09_08_03_Hourly 221M - 68.8G - | |
backups/rsync@1628010492_Tuesday_12_08_03_Hourly 247M - 68.7G - | |
backups/rsync@1628021297_Tuesday_15_08_03_Hourly 0B - 68.7G - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim /etc/apt/sources.list | |
deb http://deb.devuan.org/merged beowulf-backports main contrib | |
apt install zfs-dkms zfsutils-linux | |
zpool create backups /dev/disk/by-id/scsi-joy # single disk stripe pool | |
zfs create -o mountpoint=/mnt/backups backups/rsync | |
zfs set compression=gzip-7 backups/rsync | |
zfs set dedup=on backups/rsync # optional, know your memory requirements |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment