#!/bin/bash

# This file is a simple wrapper around barman which records good recovery points in consul.
# Note that barman is configured for each cluster independently
#
# Usage:   ./backup-all $cluster $remote
# Example: ./backup-all sitedb media33.justin.tv

cluster=${1}
remote=${2}
ssh barman@${remote} "barman backup ${cluster}"

# We set the 'latest' in consul into the future to allow enough time
# to restore to a consistent state when using `barman restore last`.
# The primary consumer of this is the staging sitedb mirrors.
latest=$(date --utc -d '+10 minutes' +'%F %T')
curl -X PUT -d "${latest} UTC" http://consul.internal.justin.tv/v1/kv/backups/db/${cluster}/latest?dc=sfo01
