musicbrainz-server/admin/RunSearchIndexesDump
yvanzo 9826da1bf4 Rework the output of Bash scripts running via cron
Since cron commands timestamp the output of scripts, the timestamps
added by scripts run using cron are redundant and thus removed here.

When running from a terminal without logging for development purpose,
bash scripts will prefix their output with local relative timestamps.

Scripts for slave servers are not modified for now.
2022-03-21 08:38:39 +00:00

73 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -o errexit
if [[ -t 1 ]]
then
exec 2>&1 | ts '%X %Z'
fi
exec 220>/tmp/.RunSearchIndexesDump.lock || exit 1
# Will be automatically released when the script exits.
flock -n 220 || { echo "Failed to obtain lock. Another instance is running?" >&2; exit 1; }
# This is to help with disk space monitoring - run "df" before and after
echo "Disk space when RunSearchIndexesDump starts:" ; df -m
trap 'echo "Disk space when RunSearchIndexesDump ends:" ; df -m' 0
MB_SERVER_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd)
cd "$MB_SERVER_ROOT"
source admin/config.sh
. ./admin/functions.sh
make_temp_dir
DUMP_DIR="$SEARCH_INDEXES_DUMP_DIR"
DUMP_STAMP=`TZ=UTC date +'%Y%m%d-%H%M%S'`
# Create necessary directories and set permissions.
mkdir -m "$SEARCH_INDEXES_DUMP_DIR_MODE" -p "$DUMP_DIR/$DUMP_STAMP"
chown "$SEARCH_INDEXES_DUMP_USER:$SEARCH_INDEXES_DUMP_GROUP" \
"$DUMP_DIR" \
"$DUMP_DIR"/"$DUMP_STAMP"
echo Requesting SolrCloud backups
BACKUP_STAMP="$DUMP_STAMP" \
./admin/RequestSolrCloudBackups \
|| exit $?
echo Retrieving SolrCloud backups
MBS_ADMIN_CONFIG=config.search-indexes-dump.sh \
./bin/rsync-solrcloud-backups "$TEMP_DIR" \
|| exit $?
echo Making a search indexes dump
BACKUP_STAMP="$DUMP_STAMP" \
./admin/BundleSearchIndexesDump \
--working-dir "$TEMP_DIR" \
|| exit $?
echo Copying the dump to the local FTP directory
chown "$SEARCH_INDEXES_DUMP_USER:$SEARCH_INDEXES_DUMP_GROUP" "$TEMP_DIR"/*
chmod "$SEARCH_INDEXES_DUMP_FILE_MODE" "$TEMP_DIR"/*
mv "$TEMP_DIR"/* "$DUMP_DIR"/"$DUMP_STAMP"/
# Finally create a "latest-is" file, indicating the export we just did.
rm -rf "$DUMP_DIR"/latest-is-*
> "$DUMP_DIR"/latest-is-"$DUMP_STAMP"
chmod "$SEARCH_INDEXES_DUMP_FILE_MODE" "$DUMP_DIR"/latest-is-"$DUMP_STAMP"
chown "$SEARCH_INDEXES_DUMP_USER:$SEARCH_INDEXES_DUMP_GROUP" "$DUMP_DIR"/latest-is-"$DUMP_STAMP"
# Finally finally, create a LATEST file whose *contents* are this export's tag
rm -rf "$DUMP_DIR"/LATEST
echo "$DUMP_STAMP" > "$DUMP_DIR"/LATEST
chmod "$SEARCH_INDEXES_DUMP_FILE_MODE" "$DUMP_DIR"/LATEST
chown "$SEARCH_INDEXES_DUMP_USER:$SEARCH_INDEXES_DUMP_GROUP" "$DUMP_DIR"/LATEST
echo Deleting old full exports from the local FTP directory
./bin/delete-old-fullexports -k -r "$DUMP_DIR"
echo Syncing the local FTP directory with the FTP server
MBS_ADMIN_CONFIG=config.search-indexes-dump.sh ./bin/rsync-fullexport-files