-
-
Save erikw/eeec35be33e847c211acd886ffb145d5 to your computer and use it in GitHub Desktop.
Revisions
-
erikw revised this gist
Mar 6, 2020 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -30,9 +30,11 @@ echo -e "> Running command \"${cmd}\".\n" eval "$cmd" ecode="$?" echo -e "\n> Command exit code: ${ecode}" snapshot_post="${zfs_pool}@${snapshot_prefix}_post" zfs snapshot -r $snapshot_post echo "> New post snapshot created: ${snapshot_post}" echo "> See the diff between them using:" -
erikw revised this gist
Jun 23, 2018 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -43,4 +43,7 @@ echo "> Destroy these snapshots with:" echo "zfs destroy -r ${snapshot_pre} && zfs destroy -r ${snapshot_post}" echo "> Destroy all snapshots created with znp:" echo "zfs list -H -o name -t snapshot | grep "${zfs_pool}@znp_" | xargs -n1 zfs destroy -r" echo "> Destroy the 10 oldest snapshot pairs created with znp:" echo "zfs list -H -o name -t snapshot | grep "${zfs_pool}@znp_" | head -20 | xargs -n1 zfs destroy -r" -
erikw revised this gist
Jun 5, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -35,7 +35,7 @@ zfs snapshot -r $snapshot_post echo -e "\n> New post snapshot created: ${snapshot_post}" echo "> See the diff between them using:" # Tip: add -t to xargs to print every individual command. echo "zfs list -t snapshot -o name | grep ${snapshot_prefix} | cut -d@ -f1 | uniq | xargs -I{} -n1 sh -c 'zfs diff -F {}@${snapshot_prefix}_pre {}@${snapshot_prefix}_post 2>/dev/null'" -
erikw revised this gist
Jun 5, 2018 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -34,11 +34,13 @@ snapshot_post="${zfs_pool}@${snapshot_prefix}_post" zfs snapshot -r $snapshot_post echo -e "\n> New post snapshot created: ${snapshot_post}" echo "> See the diff between them using" # Tip: add -t to xargs to print every individual command. echo "zfs list -t snapshot -o name | grep ${snapshot_prefix} | cut -d@ -f1 | uniq | xargs -I{} -n1 sh -c 'zfs diff -F {}@${snapshot_prefix}_pre {}@${snapshot_prefix}_post 2>/dev/null'" echo "> Destroy these snapshots with:" echo "zfs destroy -r ${snapshot_pre} && zfs destroy -r ${snapshot_post}" echo "> Destroy all snapshots created with znp:" echo "zfs list -H -o name -t snapshot | grep "${zfs_pool}@znp_" | xargs -n1 zfs destroy -r" -
erikw revised this gist
May 29, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ # Analogous to my snp script for BTRFS: https://gist.github.com/erikw/5229436 # Usage: $ znp <commands> # e.g.: $ znp pgk upgrade # e.g.: $ znp portmaster -aG # e.g.: $ znp freebsd-upgrade install zfs_pool=zroot -
erikw revised this gist
May 29, 2018 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -28,14 +28,12 @@ echo "> New pre snapshot created: ${snapshot_pre}" echo -e "> Running command \"${cmd}\".\n" eval "$cmd" snapshot_post="${zfs_pool}@${snapshot_prefix}_post" zfs snapshot -r $snapshot_post echo -e "\n> New post snapshot created: ${snapshot_post}" echo -e "\n> Destroy these snapshots with:" echo "zfs destroy -r ${snapshot_pre} && zfs destroy -r ${snapshot_post}" echo "> See the diff between them using" -
erikw created this gist
May 29, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ #!/usr/bin/env bash # Runs a command wrapped in ZFS pre-post snapshots. The whole data pool is recursively snapshotted. # Analogous to my snp script for BTRFS: https://gist.github.com/erikw/5229436 # Usage: $ znp <commands> # e.g.: $ znp pgk upgrade # e.g.: $ znp freebsd-upgrade install zfs_pool=zroot log_path="/var/local/log/znp" date=$(date "+%Y-%m-%d-%H%M%S") snapshot_prefix="znp_${date}" log_file="${log_path}/znp_${date}.log" ! [ -d $log_path ] && mkdir -p $log_path # Log stdout and stderr. Reference: http://stackoverflow.com/questions/3173131/redirect-copy-of-stdout-to-log-file-from-within-bash-script-itself exec > >(tee -a "$log_file") exec 2> >(tee -a "$log_file" >&2) cmd="$@" echo "> Logging to: ${log_file}" # snapper create --type=pre --cleanup-algorithm=number --print-number --description="${cmd}" snapshot_pre="${zfs_pool}@${snapshot_prefix}_pre" zfs snapshot -r $snapshot_pre echo "> New pre snapshot created: ${snapshot_pre}" echo -e "> Running command \"${cmd}\".\n" eval "$cmd" echo -e "\n" snapshot_post="${zfs_pool}@${snapshot_prefix}_post" zfs snapshot -r $snapshot_post echo "> New post snapshot created: ${snapshot_post}" echo -e "\n" echo "> Destroy these snapshots with:" echo "zfs destroy -r ${snapshot_pre} && zfs destroy -r ${snapshot_post}" echo "> See the diff between them using" echo "zfs diff ${snapshot_pre} ${snapshot_post}" echo "> Destroy all snapshots created with znp:" echo "zfs list -H -o name -t snapshot | grep "${zfs_pool}@znp_" | xargs -n1 zfs destroy -r"