homeserver/roles/mgrote.sanoid/templates/sanoid-cron.sh

41 lines
897 B
Bash
Raw Normal View History

2020-08-18 11:57:53 +02:00
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LOCKDIR=${HOME}/.cache
# Get an exclusive lock or exit
function exlock() {
exec {lock_fd}>${LOCKDIR}/$(basename $0).lock
flock -nx "$lock_fd"
if [[ $? == 1 ]]; then
exit 1
fi
}
# Cleanup lock file and exit
function unlock() {
rm "${LOCKDIR}/$(basename $0).lock"
[[ -n $1 ]] && exit $1
exit 0
}
# Damit prueft ob das Script ob es schon laeuft
exlock
(
echo "--------------------------------------------------"
echo $(date) sanoid start
echo ""
/usr/local/bin/sanoid --cron --verbose
echo ""
zfs list hdd_data_raidz/data -o space -t snapshot
zfs list hdd_data_raidz/data/videos -o space -t snapshot
2020-08-18 11:57:53 +02:00
echo $(date) sanoid end
echo "--------------------------------------------------"
) >> /var/log/sanoid-cron.log 2>&1 &
#Hiermit wird die Lockdatei geloescht
unlock