#!/bin/sh
#/ Usage: ghe-backup-es-tarball
#/ Take a tarball snapshot of all Elasticsearch data.
#/
#/ Note: This script typically isn't called directly. It's invoked by the
#/ ghe-backup when the tarball strategy is used.
set -e

# Bring in the backup configuration
cd $(dirname "$0")/../..
. share/github-backup-utils/ghe-backup-config

# Snapshot all Elasticsearch data or fake it when no /data/elasticsearch
# directory exists.
echo "
    if [ -d '$GHE_REMOTE_DATA_USER_DIR/elasticsearch' ]; then
        ghe-export-es-indices
    else
        tar cvf - --files-from /dev/null
    fi
" | ghe-ssh "$GHE_HOSTNAME" /bin/sh > "$GHE_SNAPSHOT_DIR"/elasticsearch.tar
