|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -eEuo pipefail |
| 4 | + |
| 5 | +if [ -n "${DEBUG:-}" ]; then |
| 6 | + set -x |
| 7 | +fi |
| 8 | + |
| 9 | +function confirm() { |
| 10 | + read -p "$1 [y/n] " confirmation |
| 11 | + if [ "$confirmation" != "y" ]; then |
| 12 | + echo "Canceled. 😅" |
| 13 | + exit |
| 14 | + fi |
| 15 | +} |
| 16 | + |
| 17 | +# The purpose of this script is to make it easy to reset a local self-hosted |
| 18 | +# install to a clean state, optionally targeting a particular version. |
| 19 | + |
| 20 | +function clean() { |
| 21 | + # If we have a version given, validate it. |
| 22 | + # ---------------------------------------- |
| 23 | + # Note that arbitrary git refs won't work, because the *_IMAGE variables in |
| 24 | + # .env will almost certainly point to :latest. Tagged releases are generally |
| 25 | + # the only refs where these component versions are pinned, so enforce that |
| 26 | + # we're targeting a valid tag here. Do this early in order to fail fast. |
| 27 | + if [ -n "$version" ]; then |
| 28 | + set +e |
| 29 | + git rev-parse --verify --quiet "refs/tags/$version" >/dev/null |
| 30 | + if [ $? -gt 0 ]; then |
| 31 | + echo "Bad version: $version" |
| 32 | + exit |
| 33 | + fi |
| 34 | + set -e |
| 35 | + fi |
| 36 | + |
| 37 | + false "noooo" |
| 38 | + |
| 39 | + # Make sure they mean it. |
| 40 | + if [ "${FORCE_CLEAN:-}" == "1" ]; then |
| 41 | + echo "☠️ Seeing FORCE=1, forcing cleanup." |
| 42 | + echo |
| 43 | + else |
| 44 | + confirm "☠️ Warning! 😳 This is highly destructive! 😱 Are you sure you wish to proceed?" |
| 45 | + echo "Okay ... good luck! 😰" |
| 46 | + fi |
| 47 | + |
| 48 | + # Hit the reset button. |
| 49 | + $dc down --volumes --remove-orphans --rmi local |
| 50 | + |
| 51 | + # Remove any remaining (likely external) volumes with name matching 'sentry-.*'. |
| 52 | + for volume in $(docker volume list --format '{{ .Name }}' | grep '^sentry-'); do |
| 53 | + docker volume remove $volume >/dev/null && |
| 54 | + echo "Removed volume: $volume" || |
| 55 | + echo "Skipped volume: $volume" |
| 56 | + done |
| 57 | + |
| 58 | + # If we have a version given, switch to it. |
| 59 | + if [ -n "$version" ]; then |
| 60 | + git checkout "$version" |
| 61 | + fi |
| 62 | +} |
| 63 | + |
| 64 | +function backup() { |
| 65 | + chmod +w $(pwd)/sentry |
| 66 | + docker-compose run -v $(pwd)/sentry:/sentry-data/backup --rm -T -e SENTRY_LOG_LEVEL=CRITICAL web export /sentry-data/backup/backup.json |
| 67 | +} |
| 68 | + |
| 69 | +function restore() { |
| 70 | + docker-compose run --rm -T web import /etc/sentry/backup.json |
| 71 | +} |
| 72 | + |
| 73 | +# Needed variables to source error-handling script |
| 74 | +MINIMIZE_DOWNTIME="${MINIMIZE_DOWNTIME:-}" |
| 75 | +STOP_TIMEOUT=60 |
| 76 | + |
| 77 | +# Save logs in order to send envelope to Sentry |
| 78 | +log_file=sentry_"$cmd"_log-$(date +'%Y-%m-%d_%H-%M-%S').txt |
| 79 | +exec &> >(tee -a "$log_file") |
| 80 | +version="" |
| 81 | + |
| 82 | +while (($#)); do |
| 83 | + case "$1" in |
| 84 | + --report-self-hosted-issues) REPORT_SELF_HOSTED_ISSUES=1 ;; |
| 85 | + --no-report-self-hosted-issues) REPORT_SELF_HOSTED_ISSUES=0 ;; |
| 86 | + *) version=$1 ;; |
| 87 | + esac |
| 88 | + shift |
| 89 | +done |
| 90 | + |
| 91 | +# Source files needed to set up error-handling |
| 92 | +source install/dc-detect-version.sh |
| 93 | +source install/detect-platform.sh |
| 94 | +source install/error-handling.sh |
| 95 | +trap_with_arg cleanup ERR INT TERM EXIT |
0 commit comments