mirror of
https://github.com/getsentry/self-hosted.git
synced 2025-12-08 19:46:14 +00:00
Add Backup/restore scripts (#2029)
* add backup/restore scripts * refactor utils to scripts
This commit is contained in:
parent
c0ff2f49c9
commit
8fc2933c20
4
.gitignore
vendored
4
.gitignore
vendored
@ -37,7 +37,9 @@ var/
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
sentry_install_log*.txt
|
||||
sentry_clean_log*.txt
|
||||
sentry_reset_log*.txt
|
||||
sentry_restore_log*.txt
|
||||
sentry_backup_log*.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
|
||||
95
scripts/_lib.sh
Executable file
95
scripts/_lib.sh
Executable file
@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eEuo pipefail
|
||||
|
||||
if [ -n "${DEBUG:-}" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
function confirm() {
|
||||
read -p "$1 [y/n] " confirmation
|
||||
if [ "$confirmation" != "y" ]; then
|
||||
echo "Canceled. 😅"
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
# The purpose of this script is to make it easy to reset a local self-hosted
|
||||
# install to a clean state, optionally targeting a particular version.
|
||||
|
||||
function clean() {
|
||||
# If we have a version given, validate it.
|
||||
# ----------------------------------------
|
||||
# Note that arbitrary git refs won't work, because the *_IMAGE variables in
|
||||
# .env will almost certainly point to :latest. Tagged releases are generally
|
||||
# the only refs where these component versions are pinned, so enforce that
|
||||
# we're targeting a valid tag here. Do this early in order to fail fast.
|
||||
if [ -n "$version" ]; then
|
||||
set +e
|
||||
git rev-parse --verify --quiet "refs/tags/$version" >/dev/null
|
||||
if [ $? -gt 0 ]; then
|
||||
echo "Bad version: $version"
|
||||
exit
|
||||
fi
|
||||
set -e
|
||||
fi
|
||||
|
||||
false "noooo"
|
||||
|
||||
# Make sure they mean it.
|
||||
if [ "${FORCE_CLEAN:-}" == "1" ]; then
|
||||
echo "☠️ Seeing FORCE=1, forcing cleanup."
|
||||
echo
|
||||
else
|
||||
confirm "☠️ Warning! 😳 This is highly destructive! 😱 Are you sure you wish to proceed?"
|
||||
echo "Okay ... good luck! 😰"
|
||||
fi
|
||||
|
||||
# Hit the reset button.
|
||||
$dc down --volumes --remove-orphans --rmi local
|
||||
|
||||
# Remove any remaining (likely external) volumes with name matching 'sentry-.*'.
|
||||
for volume in $(docker volume list --format '{{ .Name }}' | grep '^sentry-'); do
|
||||
docker volume remove $volume >/dev/null &&
|
||||
echo "Removed volume: $volume" ||
|
||||
echo "Skipped volume: $volume"
|
||||
done
|
||||
|
||||
# If we have a version given, switch to it.
|
||||
if [ -n "$version" ]; then
|
||||
git checkout "$version"
|
||||
fi
|
||||
}
|
||||
|
||||
function backup() {
|
||||
chmod +w $(pwd)/sentry
|
||||
docker-compose run -v $(pwd)/sentry:/sentry-data/backup --rm -T -e SENTRY_LOG_LEVEL=CRITICAL web export /sentry-data/backup/backup.json
|
||||
}
|
||||
|
||||
function restore() {
|
||||
docker-compose run --rm -T web import /etc/sentry/backup.json
|
||||
}
|
||||
|
||||
# Needed variables to source error-handling script
|
||||
MINIMIZE_DOWNTIME="${MINIMIZE_DOWNTIME:-}"
|
||||
STOP_TIMEOUT=60
|
||||
|
||||
# Save logs in order to send envelope to Sentry
|
||||
log_file=sentry_"$cmd"_log-$(date +'%Y-%m-%d_%H-%M-%S').txt
|
||||
exec &> >(tee -a "$log_file")
|
||||
version=""
|
||||
|
||||
while (($#)); do
|
||||
case "$1" in
|
||||
--report-self-hosted-issues) REPORT_SELF_HOSTED_ISSUES=1 ;;
|
||||
--no-report-self-hosted-issues) REPORT_SELF_HOSTED_ISSUES=0 ;;
|
||||
*) version=$1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Source files needed to set up error-handling
|
||||
source install/dc-detect-version.sh
|
||||
source install/detect-platform.sh
|
||||
source install/error-handling.sh
|
||||
trap_with_arg cleanup ERR INT TERM EXIT
|
||||
4
scripts/backup.sh
Executable file
4
scripts/backup.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
cmd=backup
|
||||
source scripts/_lib.sh
|
||||
$cmd
|
||||
4
scripts/reset.sh
Executable file
4
scripts/reset.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
cmd=reset
|
||||
source scripts/_lib.sh
|
||||
$cmd
|
||||
4
scripts/restore.sh
Executable file
4
scripts/restore.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
cmd=restore
|
||||
source scripts/_lib.sh
|
||||
$cmd
|
||||
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
FORCE_CLEAN=1 "./utilities/clean.sh"
|
||||
FORCE_CLEAN=1 "./scripts/reset.sh"
|
||||
fail=0
|
||||
for test_file in _unit-test/*-test.sh; do
|
||||
echo "🙈 Running $test_file ..."
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
log_name=clean
|
||||
|
||||
source utilities/set-up-error-reporting-for-scripts.sh
|
||||
source utilities/docker-cleanup.sh
|
||||
@ -1,57 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# The purpose of this script is to make it easy to reset a local self-hosted
|
||||
# install to a clean state, optionally targeting a particular version.
|
||||
|
||||
if [ -n "${DEBUG:-}" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
function confirm() {
|
||||
read -p "$1 [y/n] " confirmation
|
||||
if [ "$confirmation" != "y" ]; then
|
||||
echo "Canceled. 😅"
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
# If we have a version given, validate it.
|
||||
# ----------------------------------------
|
||||
# Note that arbitrary git refs won't work, because the *_IMAGE variables in
|
||||
# .env will almost certainly point to :latest. Tagged releases are generally
|
||||
# the only refs where these component versions are pinned, so enforce that
|
||||
# we're targeting a valid tag here. Do this early in order to fail fast.
|
||||
|
||||
if [ -n "$version" ]; then
|
||||
set +e
|
||||
git rev-parse --verify --quiet "refs/tags/$version" >/dev/null
|
||||
if [ $? -gt 0 ]; then
|
||||
echo "Bad version: $version"
|
||||
exit
|
||||
fi
|
||||
set -e
|
||||
fi
|
||||
|
||||
# Make sure they mean it.
|
||||
if [ "${FORCE_CLEAN:-}" == "1" ]; then
|
||||
echo "☠️ Seeing FORCE=1, forcing cleanup."
|
||||
echo
|
||||
else
|
||||
confirm "☠️ Warning! 😳 This is highly destructive! 😱 Are you sure you wish to proceed?"
|
||||
echo "Okay ... good luck! 😰"
|
||||
fi
|
||||
|
||||
# Hit the reset button.
|
||||
$dc down --volumes --remove-orphans --rmi local
|
||||
|
||||
# Remove any remaining (likely external) volumes with name matching 'sentry-.*'.
|
||||
for volume in $(docker volume list --format '{{ .Name }}' | grep '^sentry-'); do
|
||||
docker volume remove $volume >/dev/null &&
|
||||
echo "Removed volume: $volume" ||
|
||||
echo "Skipped volume: $volume"
|
||||
done
|
||||
|
||||
# If we have a version given, switch to it.
|
||||
if [ -n "$version" ]; then
|
||||
git checkout "$version"
|
||||
fi
|
||||
@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Needed variables to source error-handling script
|
||||
MINIMIZE_DOWNTIME="${MINIMIZE_DOWNTIME:-}"
|
||||
STOP_TIMEOUT=60
|
||||
|
||||
# Save logs in order to send envelope to Sentry
|
||||
log_file=sentry_"$log_name"_log-$(date +'%Y-%m-%d_%H-%M-%S').txt
|
||||
exec &> >(tee -a "$log_file")
|
||||
version=""
|
||||
|
||||
while (($#)); do
|
||||
case "$1" in
|
||||
--report-self-hosted-issues) REPORT_SELF_HOSTED_ISSUES=1 ;;
|
||||
--no-report-self-hosted-issues) REPORT_SELF_HOSTED_ISSUES=0 ;;
|
||||
*) version=$1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Source files needed to set up error-handling
|
||||
source install/dc-detect-version.sh
|
||||
source install/detect-platform.sh
|
||||
source install/error-handling.sh
|
||||
trap_with_arg cleanup ERR INT TERM EXIT
|
||||
Loading…
x
Reference in New Issue
Block a user