For version before 23.3.1 run this from self-hosted-sentry directory:
chmod o+w sentry docker-compose run -v $(pwd)/sentry:/sentry-data/backup --rm -T -e SENTRY_LOG_LEVEL=CRITICAL web export /sentry-data/backup/backup.json mv sentry/backup.json /root/sentry-config-backup_$(date +%F).json
The above will only backup users and projects, not historic event data.