mirror of
https://github.com/kneutron/ansitest.git
synced 2025-01-30 05:02:54 +08:00
Add files via upload
This commit is contained in:
parent
21729e53da
commit
a4e18ca230
67
ZFS/zfs-killmonth-snaps-debianfix.sh
Normal file
67
ZFS/zfs-killmonth-snaps-debianfix.sh
Normal file
@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 2020.1005 mod for auto-month
|
||||
# 2021.0303 fixed date pmonth for debian
|
||||
|
||||
# test for interactive shell / OK to ask for input
|
||||
intera=1
|
||||
[ `echo $- |grep i |wc -l` -gt 0 ] && intera=0
|
||||
|
||||
# TODO comment if you want auto
|
||||
#mymonth=Mar
|
||||
outfile=/tmp/zfs-killmonth-tmp.txt
|
||||
|
||||
source ~/bin/failexit.mrg
|
||||
|
||||
#zfs-list-snaps--boojum.sh |grep virtb |grep Jan |awk '{print $1}' |xargs -n1 -t zfs-killsnaps.sh
|
||||
|
||||
# REF: https://stackoverflow.com/questions/13168463/using-date-command-to-get-previous-current-and-next-month
|
||||
|
||||
# The fuzz in units can cause problems with relative items.
|
||||
# To determine the previous month more reliably, you can ask for the month before the 15th of current month
|
||||
#pmonth=$(date --date="$(date +%Y-%m-15) -2 month" |awk '{print $2}')
|
||||
# 2021.0303 fix for debian
|
||||
pmonth=$(date -d '2 months ago' |awk '{print $3}')
|
||||
|
||||
# arg NOT blank
|
||||
[ "$1" = "" ] || mymonth=$1
|
||||
# arg IS blank
|
||||
[ "$1" = "" ] && [ "$mymonth" = "" ] && mymonth=$pmonth
|
||||
|
||||
# sanity check for valid month
|
||||
validmo="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
|
||||
sanity=$(echo "$validmo" |grep -c $mymonth) # will NOT allow "July", only 3-letter
|
||||
echo "$sanity"
|
||||
|
||||
if [ $sanity -eq 0 ]; then
|
||||
failexit 12 "! Invalid month specified: $mymonth"
|
||||
fi
|
||||
|
||||
echo "`date` - DF before:" > $outfile
|
||||
df -h -T |head -n 1 >> $outfile
|
||||
df -h -T |grep zfs >> $outfile
|
||||
|
||||
# could use more error checking if $mymonth = 0 lines...
|
||||
numlines=`zfs-list-snaps--boojum.sh |grep $mymonth |wc -l`
|
||||
if [ $numlines -gt 0 ]; then
|
||||
echo "o KILLING THESE SNAPSHOTS:" >> $outfile
|
||||
zfs-list-snaps--boojum.sh |grep $mymonth >> $outfile # full dump of snapshots to delete
|
||||
|
||||
echo "Killing $numlines snapshots for $mymonth ... PK to proceed!"
|
||||
[ $intera -gt 0 ] && read
|
||||
else
|
||||
failexit 101 "No $mymonth snapshots found to kill!"
|
||||
fi
|
||||
|
||||
# killzem
|
||||
zfs-list-snaps--boojum.sh |grep $mymonth |awk '{print $1}' |xargs -n1 -t zfs-killsnaps.sh
|
||||
|
||||
# review
|
||||
[ $intera -gt 0 ] && zfs-list-snaps--boojum.sh |less
|
||||
|
||||
echo "`date` - DF after:" >> $outfile
|
||||
#df -h >> $outfile
|
||||
df -h -T |head -n 1 >> $outfile
|
||||
df -h -T |grep zfs >> $outfile
|
||||
|
||||
[ $intera -gt 0 ] && less $outfile
|
63
ZFS/zfs-killmonth-snaps.sh
Normal file
63
ZFS/zfs-killmonth-snaps.sh
Normal file
@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 2020.1005 mod for auto-month
|
||||
|
||||
# test for interactive shell / OK to ask for input
|
||||
intera=1
|
||||
[ `echo $- |grep i |wc -l` -gt 0 ] && intera=0
|
||||
|
||||
# TODO comment if you want auto
|
||||
#mymonth=Mar
|
||||
outfile=/tmp/zfs-killmonth-tmp.txt
|
||||
|
||||
source ~/bin/failexit.mrg
|
||||
|
||||
#zfs-list-snaps--boojum.sh |grep virtb |grep Jan |awk '{print $1}' |xargs -n1 -t zfs-killsnaps.sh
|
||||
|
||||
# REF: https://stackoverflow.com/questions/13168463/using-date-command-to-get-previous-current-and-next-month
|
||||
|
||||
# The fuzz in units can cause problems with relative items.
|
||||
# To determine the previous month more reliably, you can ask for the month before the 15th of current month
|
||||
pmonth=$(date --date="$(date +%Y-%m-15) -2 month" |awk '{print $2}')
|
||||
|
||||
# arg NOT blank
|
||||
[ "$1" = "" ] || mymonth=$1
|
||||
# arg IS blank
|
||||
[ "$1" = "" ] && [ "$mymonth" = "" ] && mymonth=$pmonth
|
||||
|
||||
# sanity check for valid month
|
||||
validmo="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
|
||||
sanity=`echo $validmo |grep -c $mymonth` # will NOT allow "July", only 3-letter
|
||||
|
||||
if [ $sanity -eq 0 ]; then
|
||||
failexit 12 "! Invalid month specified: $mymonth"
|
||||
fi
|
||||
|
||||
echo "`date` - DF before:" > $outfile
|
||||
df -h -T |head -n 1 >> $outfile
|
||||
df -h -T |grep zfs >> $outfile
|
||||
|
||||
# could use more error checking if $mymonth = 0 lines...
|
||||
numlines=`zfs-list-snaps--boojum.sh |grep $mymonth |wc -l`
|
||||
if [ $numlines -gt 0 ]; then
|
||||
echo "o KILLING THESE SNAPSHOTS:" >> $outfile
|
||||
zfs-list-snaps--boojum.sh |grep $mymonth >> $outfile # full dump of snapshots to delete
|
||||
|
||||
echo "Killing $numlines snapshots for $mymonth ... PK to proceed!"
|
||||
[ $intera -gt 0 ] && read
|
||||
else
|
||||
failexit 101 "No $mymonth snapshots found to kill!"
|
||||
fi
|
||||
|
||||
# killzem
|
||||
zfs-list-snaps--boojum.sh |grep $mymonth |awk '{print $1}' |xargs -n1 -t zfs-killsnaps.sh
|
||||
|
||||
# review
|
||||
[ $intera -gt 0 ] && zfs-list-snaps--boojum.sh |less
|
||||
|
||||
echo "`date` - DF after:" >> $outfile
|
||||
#df -h >> $outfile
|
||||
df -h -T |head -n 1 >> $outfile
|
||||
df -h -T |grep zfs >> $outfile
|
||||
|
||||
[ $intera -gt 0 ] && less $outfile
|
Loading…
x
Reference in New Issue
Block a user