sqlite3 backup
This commit is contained in:
parent
a33a3c519c
commit
6f32d49646
@ -20,7 +20,7 @@
|
||||
* Set up Docker Swarm and [`abra`]
|
||||
* Deploy [`coop-cloud/traefik`]
|
||||
* `abra app new gotosocial`
|
||||
* `abra app config <app-domain>`
|
||||
* `abra app config <app-domain>` (choose database type now, migration is possible but annoying)
|
||||
* `abra app deploy <app-domain>`
|
||||
|
||||
Note: This deployment can be pretty wonky on instances with ≤2GB of available RAM or <4 cores. Please be patient and check the logs, if it's something related to postgres not being launched yet then just wait, gts will restart itself until the database is available.
|
||||
|
@ -18,10 +18,8 @@ services:
|
||||
image: postgres:17.2
|
||||
deploy:
|
||||
labels:
|
||||
backupbot.backup: "true"
|
||||
backupbot.backup.pre-hook: "/pg_backup.sh backup"
|
||||
backupbot.backup.path: "/var/lib/postgresql/data/backup.sql"
|
||||
backupbot.restore: "true"
|
||||
backupbot.restore.post-hook: "/pg_backup.sh restore"
|
||||
environment:
|
||||
- POSTGRES_DB=gotosocial
|
||||
|
10
compose.yml
10
compose.yml
@ -7,6 +7,9 @@ services:
|
||||
- source: entrypoint
|
||||
target: /custom-entrypoint.sh
|
||||
mode: 0555
|
||||
- source: sqlite_backup
|
||||
target: /sqlite_backup.sh
|
||||
mode: 0555
|
||||
entrypoint: /custom-entrypoint.sh
|
||||
environment:
|
||||
- GTS_HOST=${DOMAIN}
|
||||
@ -28,6 +31,10 @@ services:
|
||||
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}"
|
||||
- "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure"
|
||||
- "coop-cloud.${STACK_NAME}.version=1.0.0+0.17.3"
|
||||
- "backupbot.backup=true"
|
||||
- "backupbot.backup.pre-hook=/sqlite_backup.sh"
|
||||
- "backupbot.backup.path=/gotosocial/sqlite_bak/backup.sql"
|
||||
- "backupbot.backup.post-hook=rm -rfv /gotosocial/sqlite_bak"
|
||||
healthcheck:
|
||||
test: wget --no-verbose --tries=1 --spider http://localhost:8080/readyz || exit 1
|
||||
interval: 120s
|
||||
@ -50,3 +57,6 @@ configs:
|
||||
name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_VERSION}
|
||||
file: entrypoint.sh.tmpl
|
||||
template_driver: golang
|
||||
sqlite_backup:
|
||||
name: ${STACK_NAME}_sqlite_backup_${PG_BACKUP_VERSION}
|
||||
file: sqlite_backup.sh
|
||||
|
31
sqlite_backup.sh
Normal file
31
sqlite_backup.sh
Normal file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
URL="https://github.com/CompuRoot/static-sqlite3/releases/download/3.46.1_01/sqlite3"
|
||||
BACKUP_DIR="sqlite_bak"
|
||||
DATABASE_FILE="/gotosocial/storage/sqlite.db"
|
||||
BACKUP_FILE="backup.sql"
|
||||
|
||||
mkdir -p "$BACKUP_DIR" && cd "$BACKUP_DIR"
|
||||
|
||||
echo "Downloading $URL..."
|
||||
wget -q "$URL"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to download the binary file." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
chmod +x ./sqlite3
|
||||
|
||||
if [ ! -f "$DATABASE_FILE" ]; then
|
||||
echo "The SQLite database file '$DATABASE_FILE' does not exist in the extracted directory." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Backing up $DATABASE_FILE to $BACKUP_FILE..."
|
||||
./sqlite3 $DATABASE_FILE ".backup '$BACKUP_FILE'"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to backup the database." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Backup completed successfully. The backup is stored in $BACKUP_FILE."
|
Loading…
x
Reference in New Issue
Block a user