source: src-sh/warden/scripts/backend/cronsnap.sh @ 0988d23

9.1-release9.2-releasereleng/10.0releng/10.0.1
Last change on this file since 0988d23 was 0988d23, checked in by Kris Moore <kris@…>, 12 months ago

Add my working directory for the new warden backend changes.

Includes patches from John Hixson (john@…) to change
how warden uses "nicknames" instead of IP addresses for jail
identification.

  • Property mode set to 100755
File size: 1.8 KB
Line 
1#!/bin/sh
2# Prints a listing of the installed jails
3######################################################################
4
5# Source our functions
6PROGDIR="/usr/local/share/warden"
7
8# Source our variables
9. ${PROGDIR}/scripts/backend/functions.sh
10
11# Check if we have any jails
12if [ ! -d "${JDIR}" ]
13then
14  exit 0
15fi
16
17cd ${JDIR}
18
19for i in `ls -d .*.meta 2>/dev/null`
20do
21  if [ ! -e "${i}/cron" ] ; then continue ; fi
22  if [ ! -e "${i}/cron-keep" ] ; then continue ; fi
23
24  jHOST="`cat ${i}/host`"
25  JAILDIR="${JDIR}/${jHOST}"
26
27  if [ ! -d "${JAILDIR}" ] ; then continue ; fi
28
29  CRONFREQ="`cat ${i}/cron`"
30  CRONKEEPDAYS="`cat ${i}/cron-keep`"
31
32  # Figure out if we need to create a new snapshot
33  snaps=$(listZFSSnap "${JAILDIR}")
34  lastsnap=`echo $snaps | rev | cut -d " " -f 1 | rev`
35  needSnap=0
36  zdate=`date +%Y%m%d-%H%M%S`
37  if [ "$CRONFREQ" = "daily" ] ; then
38     #echo "Checking for daily snapshots to ${jHOST}..."
39     today=`date +%Y%m%d`
40     lastsnap=`echo $lastsnap | cut -d '-' -f 1`
41     if [ "$today" != "$lastsnap" ] ; then
42        needSnap=1
43     fi
44  else
45  # Hourly
46     #echo "Checking for hourly snapshots to ${jHOST}..."
47     today=`date +%Y%m%d`
48     hour=`date +%H`
49     lastday=`echo $lastsnap | cut -d '-' -f 1`
50     lasthour=`echo $lastsnap | cut -d '-' -f 2 | cut -c 1-2`
51     if [ "$today" != "$lastday" -o "$hour" != "$lasthour" ] ; then
52        needSnap=1
53     fi
54  fi
55  if [ "$needSnap" = "1" ] ; then
56     mkZFSSnap "${JAILDIR}"
57  fi
58
59  # Do any pruning
60  num=0
61  for snap in `echo $snaps | sort -r`
62  do
63     cur="`echo $snap | cut -d '-' -f 1`" 
64     if [ "$cur" != "$prev" ] ; then
65        num=`expr $num + 1`
66        prev="$cur"
67     fi
68     if [ $num -gt $CRONKEEPDAYS ] ; then
69        #echo "Pruning old snapshot: $snap"
70        rmZFSSnap "${JAILDIR}" "$snap"
71     fi
72  done
73done
Note: See TracBrowser for help on using the repository browser.