Closed durandalTR closed 8 years ago
I don't see this belonging in zfs-auto-snapshot - either wrap it yourself, or adjust cron to run your snapshots when you want them to.
@durandalTR: Let me think about this.
One of the problems with Linux power management is that you can wake-up a drive if you interrogate it in the wrong way. Can you suggest an easy check? Perhaps something in /proc
that can be tested with a one-liner?
Well, I thought that pdf could have a point that it was not in functional scope of the auto-snapshot tool. On the other hand it can well be in technical scope and it's a must have for some users that are interested in saving money and energy (and the world).
So, I dove into bash and made a script (and realised again how horrible bash is if you're used to java). It's pretty basic and I've not installed it in cron yet, but I have tested it on the command line. You should be able to just place it in a cron line before the auto-snapshot line, but you need 1 line for each pool. It executes what's next on the cron line when no disk of the given pool is in standby state. Do with it what you think is right.
file: /usr/bin/zstandby
#!/bin/sh print_usage () { echo "Determines if a zpool has disks that are currently in standby or if it's fully active." echo "If all disks in the pol are active/idle then the remaining command line will be executed." echo "" echo "Usage: $0 \"\" [poolname]" echo "" echo "The command line should be in double quotes." echo "If no pool name is given then the disks of ALL pools are checked." echo "Works only for pools that are created with /disk/by-id/ devices that start with 'scsi-'" echo "" echo "returns 1 if at least 1 disk is in standby, else returns the command line's result" exit 0 } # main if [ "$1" = "--help" ] || [ "$1" = "" ]; then print_usage; fi COMMAND="$1" ZPOOL=$(env zpool status $2) DISKS=$(env echo "$ZPOOL" | grep -i -o '.*scsi-.*') IFS=' ' ALL_ACTIVE=1 echo "$DISKS" | while read -r whitespace disk state rd wr chk; do # echo "disk: [$disk]" SPINSTATE=$(env hdparm -C /dev/disk/by-id/$disk | grep -i -o standby) # echo "spin: [$SPIN]" if [ "$SPINSTATE" = "standby" ] then # found a disk in standby - don't perform the commandline echo "found a disk in standby: do nothing" ALL_ACTIVE=0 exit 1; fi done # somehow the exit command exits to here in stead of back to shell # something to do with a bash bug with piped loops, so check for exit flag again if [ "$?" -eq "1" ]; then exit 1; fi; # all disks are active - can perform the given command line echo "all disks active/idle, execute: $COMMAND" exec $COMMAND
Key line is
SPINSTATE=$(env hdparm -C /dev/disk/by-id/$disk | grep -i -o standby)where hdparm is used to check the drive power status, I don't know if there is a flag in /proc somewhere.
(edit: I've taken a look at the hdparm source and it queries the drive directly for it's status, so no I expect no /proc option. see https://dev.mobileread.com/svn/iliados/upstream/busybox-1.01/miscutils/hdparm.c )
I do believe there is a good spot to check for spindown state down in the subroutines in auto-snaphot if you want to expand it.
This feature request is certainly a good idea, but it probably won't happen, and development moved to the zfsonlinux/zfs-auto-snapshot repository, so I will close this ticket as stale.
Some servers have their disks in standby (spinned down) when not used (e.g. low power media servers), but a call to zfs-auto-snapshot causes them to spin up and consume power, wear and raises the spinup count (every 15 mins).
It would be nice for zfs-auto-snapshot to have an option not to create snapshots on pools with one or more disks in standby.
One could enable this for the more frequent snapshots (say 15m/1hr) and as a result only have snapshots made when the pool has actually been read or altered recently (like when at work on the pool during the day).