hedgedoc-expire/README.md

83 lines
3.8 KiB
Markdown
Raw Normal View History

2024-05-18 18:31:30 +02:00
# hedgedoc-expire - remove old notes
2024-05-18 19:19:06 +02:00
A Python app that can be run regularly against a Postgres Hedgedoc database to remove old notes. Notes that are expired
can be emailed to the author as a backup.
2024-05-18 18:31:30 +02:00
## Expiring old notes and revisions
2024-05-18 19:19:06 +02:00
Hedgedoc keeps notes and revisions (versions) of those notes forever. This might not be desirable, for example because
of data protection reasons. With this utility, you can remove old revisions and old notes from the database.
2024-05-18 18:31:30 +02:00
### Expiring old revisions
2024-05-19 00:34:36 +02:00
All revisions that have been created before the specified age will be removed. If all revisions are expired, the note remains available, it just won't have any revisions to revert to. Once you continue editing it, new revisions will be added.
2024-05-18 19:19:06 +02:00
2024-05-19 00:34:36 +02:00
### Expiring old notes
Notes that are being expired will be emailed to the account that initially created the note. This allows that user to restore the note, if necessary. Expiring a note will also remove all existing revisions for the note.
You will need to configure your environment for the `hedgedoc-expire` to be able to send mail. If the mail is not accepted by the mail server, the note will not be removed.
## Running `hedgedoc-expire.py`
2024-05-18 19:19:06 +02:00
Locally from the command line:
```shell
poetry run python ./hedgedoc-expire.py ...
```
From Docker Compose:
```yaml
hedgedoc-expire:
image: hedgedoc-expire
2024-05-19 00:34:36 +02:00
command: "-c -r 14 -n 95"
2024-05-18 19:19:06 +02:00
environment:
- "POSTGRES_HOSTNAME=database"
depends_on:
- database
```
## Arguments and Environment Variables
There are two main modes to run `hedgedoc-require`: check and expire. With `-c`, a report is generated on standard out.
Without it, the expiry action will be taken.
| Option | Default | Description |
|--------|---------|------------------------------------------------------------|
| -c | | Create a report which revisions and notes will be expired |
| -n | 90 | remove all notes not changed in these many days |
| -r | 7 | remove all revisions created more than these many days ago |
### Environment variables
To configure the Postgres database connection and the SMTP parameters to send mail, set these variables.
For the SMTP connection, the code assumes a standard submission protocol setup with enable StartTLS and authentication, so you will need to configure a username and password.
| Variable | Default | Description |
|-------------------|-----------------------|-------------------------------------|
| POSTGRES_DATABASE | hedgedoc | database to connect to |
| POSTGRES_HOSTNAME | localhost | host of the database server |
| POSTGRES_PASSWORD | geheim | password for the database |
| POSTGRES_PORT | 5432 | port number of the database server |
| POSTGRES_USERNAME | hedgedoc | username for the database |
| SMTP_FROM | | sender address for the expiry mails |
| SMTP_HOSTNAME | localhost | mail server hostname |
| SMTP_PASSWORD | | SMTP password |
| SMTP_PORT | 587 | port to connect to |
| SMTP_USERNAME | | SMTP username |
| URL | http://localhost:3000 | base URL for linking to notes |
2024-05-18 18:31:30 +02:00
## Local Development Setup
Use Docker Compose to bring up a local development environment.
* Hedgedoc: http://localhost:3000
* Adminer: http://localhost:8080/?pgsql=database&username=hedgedoc&db=hedgedoc&ns=public&password=geheim
You will need to create a user using the command line:
```sh
docker compose exec -it hedgedoc bin/manage_users --add foo@example.com --pass geheim
```