########################################################################
# Functions #
########################################################################
-# log something (basically echo it together with a timestamp)
-#
-# Set $PROGRAM to a string to have it added to the output.
-function log () {
- if [ -z "${PROGRAM}" ]; then
- echo "$(date +"%b %d %H:%M:%S") $(hostname -s) [$$] $@"
- else
- echo "$(date +"%b %d %H:%M:%S") $(hostname -s) ${PROGRAM}[$$]: $@"
- fi
-}
-
-# log the message using log() but then also send a mail
-# to the address configured in MAILTO (if non-empty)
-function log_error () {
- log "$@"
- if [ -z "${MAILTO}" ]; then
- echo "$@" | mail -e -s "[$PROGRAM@$(hostname -s)] ERROR [$$]" ${MAILTO}
- fi
-}
-
-# debug log, only output when DEBUG=1
-function debug () {
- if [ $DEBUG -eq 1 ]; then
- log "$*"
- fi
-}
+# common functions are "outsourced"
+. "${configdir}/common"
# Timestamp. Used for dinstall stat graphs
function ts() {
function pgdump_post() {
log "Creating post-daily-cron-job backup of projectb database..."
cd $base/backup
- POSTDUMP=$base/backup/dump_$(date +%Y.%m.%d-%H:%M:%S)
- pg_dump projectb > $POSTDUMP
- ln -sf $POSTDUMP current
+ POSTDUMP=$(date +%Y.%m.%d-%H:%M:%S)
+ pg_dump projectb > $base/backup/dump_$POSTDUMP
+ pg_dumpall --globals-only > $base/backup/dumpall_$POSTDUMP
+ ln -sf $base/backup/dump_$POSTDUMP current
+ ln -sf $base/backup/dumpall_$POSTDUMP currentall
+}
+
+# Load the dak-dev projectb
+function pgdakdev() {
+ cd $base/backup
+ echo "drop database projectb" | psql -p 5433 template1
+ cat currentall | psql -p 5433 template1
+ createdb -p 5433 -T template0 projectb
+ fgrep -v '\connect' `cat current` | psql -p 5433 projectb
}
# Updating various files
touch "${stagedir}/${FUNC}"
+ if [ -n "${TIME}" ]; then
+ ts "${TIME}"
+ fi
+
if [ -f "${LOCK_STOP}" ]; then
log "${LOCK_STOP} exists, exiting immediately"
exit 42
fi
-
- if [ -n "${TIME}" ]; then
- ts "${TIME}"
- fi
}
########################################################################
# How many logfiles to keep
LOGROTATE=${LOGROTATE:-400}
+# Marker for dinstall start
+DINSTALLSTART="${lockdir}/dinstallstart"
+# Marker for dinstall end
+DINSTALLEND="${lockdir}/dinstallend"
+
# Timestamps start at -1. so first gets 0
TS=-1
+touch "${DINSTALLSTART}"
ts "startup"
# Tell everyone we are doing some work
)
stage $GO
+GO=(
+ FUNC="pgdakdev"
+ TIME="dak-dev db"
+ ARGS=""
+ ERR="false"
+)
+stage $GO
+
GO=(
FUNC="expire"
TIME="expire_dumps"
log "Daily cron scripts successful, all done"
-exec > /dev/null 2>&1
+exec > "$logdir/afterdinstall.log" 2>&1
cat "$LOGFILE" | mail -s "Log for dinstall run of ${NOW}" cron@ftp-master.debian.org
# Now, at the very (successful) end of dinstall, make sure we remove
# our stage files, so the next dinstall run will do it all again.
-rm -f "${stagedir}/*"
+rm -f ${stagedir}/*
+touch "${DINSTALLEND}"