#!/bin/bash

set -e

kinit -k "daemon/$(hostname -f)"
aklog sipb

db_filename="/mit/xvm/backups/db/prod/$(date +%Y/%m/%d-%H.%M.sql.gz)"
mkdir -p "$(dirname $db_filename)"

/usr/bin/pg_dump -U "$(invirt-getconf db.user)" \
                 -h "$(invirt-getconf db.host)" \
                 "$(invirt-getconf db.dbname)" | gzip - >"$db_filename"

running_filename="/mit/xvm/log/running/prod/$(date +%Y/%m/%d-%H.%M.gz)"
mkdir -p "$(dirname $running_filename)

remctl "$(invirt-getconf remote.hostname)" web listvms | gzip - >"$running_filename"
