diff --git a/docs/docs/setup/backups.md b/docs/docs/setup/backups.md index a666881ab..14767006f 100644 --- a/docs/docs/setup/backups.md +++ b/docs/docs/setup/backups.md @@ -19,7 +19,8 @@ Specify the key as hex string via the `--key` CLI argument. docker compose run --rm app python3 manage.py backup --key "" > backup.zip.crypt ``` - +## Create a backup during update +When [updating](updates.md) SysReptor, you can use the `--backup` switch, which will create a backup before applying the update. ## Create backups via API diff --git a/docs/docs/setup/downgrades.md b/docs/docs/setup/downgrades.md new file mode 100644 index 000000000..1d531b4a0 --- /dev/null +++ b/docs/docs/setup/downgrades.md @@ -0,0 +1,40 @@ +# Downgrades +:octicons-server-24: Self-Hosted + +:octicons-heart-fill-24: Pro only + +!!! info + + Downgrading requires a backup from the version that you want downgrade to. + + +1. Create a backup + +Create a [backup](backups.md) before downgrading. + +2. Change directory to your previous version + +The update script creates a backup of your prior version's configuration. The directory is usually named `sysreptor-backup-`. +Enter the `deploy` directory within that folder. + +```bash +cd sysreptor-backup-/deploy +``` + +3. Restore the backup + +```bash +cat .zip | docker compose run --rm --no-TTY app python3 manage.py restorebackup +``` + +!!! warning + + This command deletes all present data an restores data from the backup. + Do not run without having made a backup. + + +4. Launch the old SysReptor version + +```bash +docker compose up -d +``` diff --git a/docs/docs/setup/updates.md b/docs/docs/setup/updates.md index ed5df3bdb..1e2603232 100644 --- a/docs/docs/setup/updates.md +++ b/docs/docs/setup/updates.md @@ -17,6 +17,16 @@ We recommend to create a [backup](backups.md) of your installation before updati bash sysreptor/update.sh ``` + :octicons-heart-fill-24: Pro only + + Using the `--backup` switch, a SysReptor backup will be created prior to the update. The update will fail if the backup fails. + + ```shell title="Run update script:" + bash sysreptor/update.sh --backup + ``` + + Please make sure to monitor your disk space and clean up old backups, as automatic backups might increase disk usage significantly. + === "Manual update" Download and extract the latest SysReptor release: ```shell @@ -37,6 +47,8 @@ We recommend to create a [backup](backups.md) of your installation before updati docker compose up -d ``` +Find instructions how to [downgrade](downgrades.md) to previous versions. + ## Recommended: Automatic updates We recommend to deploy automatic updates and run the script once per day. This ensures you receive updates early. @@ -56,7 +68,7 @@ crontab -e Schedule your update, e.g. every day at midnight: ```shell -0 0 * * * /bin/bash /home/yourpath/sysreptor/update.sh +0 0 * * * /bin/bash /home/yourpath/sysreptor/update.sh # Optional (pro only): --backup ``` Make sure your user has write permissions to the parent directory of your SysReptor directory. In this example, you need write permissions to `/home/yourpath/`. diff --git a/update.sh b/update.sh index f34872403..6fd974fbd 100755 --- a/update.sh +++ b/update.sh @@ -8,7 +8,7 @@ error_cleanup() { echo cd "$script_location" echo "Trying to restore your old version..." cd `dirname "$script_location"` - mv "$sysreptor_directory" "$sysreptor_directory"-failed-update-$(date -Iseconds) + mv "$sysreptor_directory" "$sysreptor_directory-failed-update-$filename_date" mv "$backup_copy" "$sysreptor_directory" cd "$sysreptor_directory"/deploy source .env @@ -19,11 +19,17 @@ error_cleanup() { fi exit -4 } +filename_date=$(date -Iseconds) +sysreptor_directory=${PWD##*/} +backup_copy="$sysreptor_directory-backup-$filename_date" +script_location="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" trap 'error_cleanup' ERR INT echo "Easy update of SysReptor" echo "" + +# Check if required commands are installed error=1 -for cmd in curl tar docker date grep +for cmd in curl tar docker date grep realpath dirname do if ! command -v "$cmd" >/dev/null @@ -44,7 +50,6 @@ then exit -1 fi # cd to script location -script_location="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" cd "$script_location" # check if parent directory writable if @@ -53,6 +58,25 @@ then echo "\"`readlink -e ..`\" not writeable. Exiting..." exit -2 fi + +# Parse CLI arguments +while [[ $# -gt 0 ]]; do + case $1 in + --backup) + BACKUP_LOCATION=`realpath "$script_location/../sysreptor-full-backup-$filename_date.zip"` + shift + ;; + -*|--*) + echo "$1 is not a valid option." + exit -7 + ;; + *) + # Positional arguments (not processed) + shift + ;; + esac +done + DOWNLOAD_URL=https://github.com/syslifters/sysreptor/releases/latest/download/setup.tar.gz DOCKER_HUB_IMAGE=syslifters/sysreptor DOCKER_HUB_LANGUAGETOOL_IMAGE=syslifters/sysreptor-languagetool @@ -77,6 +101,21 @@ else fi NEW_SYSREPTOR_VERSION=$version +if [ -n "$BACKUP_LOCATION" ]; then + cd "$script_location" + echo "" + echo "Creating full backup of your current installation..." + if + docker compose -f deploy/docker-compose.yml exec -it app python3 manage.py backup > "$BACKUP_LOCATION" 2>/dev/null + then + echo "Backup written to $BACKUP_LOCATION" + echo "" + else + echo "Backup failed. Exiting..." + exit -9 + fi +fi + echo "Downloading SysReptor from $DOWNLOAD_URL ..." curl -s -L --output ../sysreptor.tar.gz "$DOWNLOAD_URL" echo "Checking download..." @@ -86,13 +125,12 @@ then exit -5 fi -echo "Creating backup copy of your current installation..." -sysreptor_directory=${PWD##*/} -backup_copy="$sysreptor_directory"-backup-$(date -Iseconds) +echo "Creating copy of your config files..." cd .. mv "$sysreptor_directory" "$backup_copy" created_backup=1 -echo "Backup copy located at $backup_copy" +echo "Config backup located at $backup_copy" + echo "Unpacking sysreptor.tar.gz..." mkdir "$sysreptor_directory" tar xzf sysreptor.tar.gz -C "$sysreptor_directory" --strip-components=1