commit 3c7a251abdc01da44304753371b92a7d4feec6d0
parent b1762a26ce0ce3adf47795418862e2799408a3d2
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Sat, 20 Jul 2024 11:37:02 +0200
feat: information about backups
Diffstat:
2 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
@@ -34,7 +34,7 @@ at **AT THE START OF** `public/3rd/semantic-2.4.1.min.css`:
### tl;dr
-Manual installation:
+**Manual installation:**
```bash
KTISTEC_PATH="/var/www/ktistec"
@@ -45,7 +45,7 @@ cat ${KTISTEC_CSS}/semantic-*.min.css >> ${KTISTEC_CSS}/tmp
mv ${KTISTEC_CSS}/tmp ${KTISTEC_CSS}/semantic-*.min.css
```
-Docker (via [this repo's docker-compose](#docker) file):
+**Docker (via [this repo's docker-compose](#docker) file):**
```bash
docker cp ./css/purpleish.min.css ktistec:/app/public/3rd/purpleish.min.css
@@ -56,3 +56,60 @@ docker exec -ti ktistec \
mv /app/public/3rd/tmp /app/public/3rd/semantic-*.min.css
"
```
+
+## Backups
+
+### Database
+
+Database backups should be done either by file-copying **when the database is
+not in use**, i.e. as long as ktistec is not running, or better yet with the
+[`.backup`](https://sqlite.org/cli.html#special_commands_to_sqlite3_dot_commands_)
+command, which handles file-locking and changes to the database during the
+backup procedure. This enables you to make backups while ktistec is running.
+
+**Manual installation:**
+
+```bash
+KTISTEC_PATH="/var/www/ktistec"
+sqlite3 ${KTISTEC_PATH}/db/ktistec.db \
+ ".backup \"${KTISTEC_PATH}/db/ktistec_backup_$(date +%Y-%m-%d).sq3\""
+```
+
+**Docker (via [this repo's docker-compose](#docker) file):**
+
+```bash
+# the ktistec-container does not contain a sqlite CLI client,
+# so we use a new temporary alpine container instead
+docker run -ti --rm -v /var/www/ktistec/db:/db alpine:latest \
+ apk update && \
+ apk add sqlite && \
+ sqlite3 /db/ktistec.db \
+ ".backup \"/backups/ktistec_backup_$(date +%Y-%m-%d).sq3\""
+```
+
+### Uploads
+
+The uploads-folder contains images and other media files that you uploaded or
+included in one of your posts. It makes sense to back them up as well in order
+to prevent data loss.
+
+Since these are typically just image files, the easiest way to back them up is
+by archiving them with `tar`.
+
+**Manual installation:**
+
+```bash
+KTISTEC_PATH="/var/www/ktistec"
+tar -cf ${KTISTEC_PATH}/uploads_backup_$(date +%Y-%m-%d).tar \
+ ${KTISTEC_PATH}/uploads/
+```
+
+**Docker (via [this repo's docker-compose](#docker) file):**
+
+```bash
+docker exec -ti ktistec \
+ sh -c "
+ tar -cf /backups/uploads_backup_$(date +%Y-%m-%d).tar \
+ /uploads/
+ "
+```
diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml
@@ -19,6 +19,8 @@ services:
- 3000:3000
# mount volumes for db and uploads so they survive restarts
+ # mount volume for backups (optional)
volumes:
- /var/www/ktistec/db:/db
- /var/www/ktistec/uploads:/uploads
+ - /var/www/ktistec/backups:/backups