Skip to content

Commit

Permalink
Merge branch 'version-rollback' into 'main'
Browse files Browse the repository at this point in the history
Version rollback

See merge request reportcreator/reportcreator!730
  • Loading branch information
MWedl committed Oct 16, 2024
2 parents 85acf7f + 1f42046 commit 982c8ec
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 9 deletions.
3 changes: 2 additions & 1 deletion docs/docs/setup/backups.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<aes-key-as-hex>" > 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
Expand Down
40 changes: 40 additions & 0 deletions docs/docs/setup/downgrades.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Downgrades
:octicons-server-24: Self-Hosted

<span style="color:red;">:octicons-heart-fill-24: Pro only</span>

!!! 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-<date>`.
Enter the `deploy` directory within that folder.

```bash
cd sysreptor-backup-<date>/deploy
```

3. Restore the backup

```bash
cat <your-backup-file>.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
```
14 changes: 13 additions & 1 deletion docs/docs/setup/updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ We recommend to create a [backup](backups.md) of your installation before updati
bash sysreptor/update.sh
```

<span style="color:red;">:octicons-heart-fill-24: Pro only</span>

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
Expand All @@ -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.
Expand All @@ -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/`.
52 changes: 45 additions & 7 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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..."
Expand All @@ -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
Expand Down

0 comments on commit 982c8ec

Please sign in to comment.