diff options
author | Carlo Landmeter <clandmeter@alpinelinux.org> | 2018-01-29 15:31:27 +0000 |
---|---|---|
committer | Carlo Landmeter <clandmeter@alpinelinux.org> | 2018-01-29 15:35:06 +0000 |
commit | 05f986658bc04e2dc514b2c3e7777007cb6fb65c (patch) | |
tree | db49882a6aac4ea68b7fa6285c340c09466abcc5 /alpine-backup | |
download | alpine-backup-05f986658bc04e2dc514b2c3e7777007cb6fb65c.tar.bz2 alpine-backup-05f986658bc04e2dc514b2c3e7777007cb6fb65c.tar.xz |
Initial commit
Diffstat (limited to 'alpine-backup')
-rwxr-xr-x | alpine-backup | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/alpine-backup b/alpine-backup new file mode 100755 index 0000000..22af5a5 --- /dev/null +++ b/alpine-backup @@ -0,0 +1,47 @@ +#!/bin/sh + +RBU_CONF=/etc/lbu/rbu.conf + +if [ -f "$RBU_CONF" ]; then + . "$RBU_CONF" +else + echo "Cannot read $RBU_CONF" + exit 1 +fi + +# set the suffix of backup files when ecryptions is enabled +[ -n "$ENCRYPTION" ] && export SUFFIX=".$ENCRYPTION" + +# convert hostname to intra FQDN +HOSTNAME=$(hostname) +if [ -n $HOST ]; then + export FQDN="${HOSTNAME}.${HOST}.intra.alpinelinux.org" +else + export FQDN="${HOSTNAME}.intra.alpinelinux.org" +fi + +START_TS=$(date +%s) + +LOGFILE="$BACKUP_CACHE/$FQDN-$(date -u "+%Y%m%d%H%M%S").log" +lbu_commit >>"$LOGFILE" 2>&1 +ret=$? + +DURATION=$(($(date +%s)-$START_TS)) +SIZE=0 +STATUS=failed + +if [ $ret = 0 ]; then + [ -n "$ENCRYPTION" ] && SUFFIX=".$ENCRYPTION" + BACKUP="$BACKUP_LOCATION/$(hostname).apkovl.tar.gz${SUFFIX}" + SIZE=$(stat -c %s $BACKUP) + STATUS=success +fi + +ssh "$BACKUP_SERVER" mkdir -p $FQDN/logs +scp -q $LOGFILE "$BACKUP_SERVER:$FQDN/logs" + +PAYLOAD=$(printf '{ "status": "%s", "size": %u, "duration": %u }' "$STATUS" "$SIZE" "$DURATION") +JSON=$(printf '{ "host": "%s", "key": "backup", "payload": %s }' "$FQDN" "$PAYLOAD") + +mosquitto_pub -h msg.alpinelinux.org -t "monitoring/updates" -m "$JSON" + |