Compare commits
3
Commits
fix-dbbackup
...
tinyauth
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbc7c53dea | ||
|
|
eba27271d2 | ||
|
|
86fd81a825 |
@@ -26,6 +26,10 @@ REPLY_HOSTNAME=$DOMAIN
|
|||||||
|
|
||||||
RAILS_ENV=production
|
RAILS_ENV=production
|
||||||
|
|
||||||
|
# Secure page via tiny auth
|
||||||
|
# COMPOSE_FILE="$COMPOSE_FILE:compose.tinyauth.yml"
|
||||||
|
# TINY_MIDDLEWARE="sub_example_com"
|
||||||
|
|
||||||
# Number of webserver processes and threads
|
# Number of webserver processes and threads
|
||||||
# threads are per worker. See https://github.com/puma/puma
|
# threads are per worker. See https://github.com/puma/puma
|
||||||
PUMA_WORKERS=2
|
PUMA_WORKERS=2
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export LOOMIO_ENTRYPOINT_VERSION=v8
|
export LOOMIO_ENTRYPOINT_VERSION=v8
|
||||||
|
export PG_BACKUP_VERSION=v1
|
||||||
|
|
||||||
# cannot be integrated into entrypoint.sh as it requires the operator to create a user first
|
# cannot be integrated into entrypoint.sh as it requires the operator to create a user first
|
||||||
function make_last_user_admin()
|
function make_last_user_admin()
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
version: "3.8"
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
deploy:
|
||||||
|
labels:
|
||||||
|
- "traefik.http.routers.${STACK_NAME}.middlewares=${TINY_MIDDLEWARE}"
|
||||||
+12
-8
@@ -70,9 +70,8 @@ services:
|
|||||||
- "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`${EXTRA_DOMAINS})"
|
- "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`${EXTRA_DOMAINS})"
|
||||||
- "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure"
|
- "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure"
|
||||||
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}"
|
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}"
|
||||||
- "coop-cloud.${STACK_NAME}.version=5.2.0+v3.0.20"
|
- "coop-cloud.${STACK_NAME}.version=5.2.1+v3.0.20"
|
||||||
- "backupbot.backup:=${ENABLE_BACKUPS:-true}"
|
- "backupbot.backup:=${ENABLE_BACKUPS:-true}"
|
||||||
- "traefik.http.routers.${STACK_NAME}.middlewares=${STACK_NAME}"
|
|
||||||
- "traefik.http.middlewares.${STACK_NAME}.headers.accesscontrolallowmethods=GET,OPTIONS,PUT"
|
- "traefik.http.middlewares.${STACK_NAME}.headers.accesscontrolallowmethods=GET,OPTIONS,PUT"
|
||||||
- "traefik.http.middlewares.${STACK_NAME}.headers.accesscontrolallowheaders=*"
|
- "traefik.http.middlewares.${STACK_NAME}.headers.accesscontrolallowheaders=*"
|
||||||
- "traefik.http.middlewares.${STACK_NAME}.headers.accessControlAllowOriginList=https://*.${DOMAIN}"
|
- "traefik.http.middlewares.${STACK_NAME}.headers.accessControlAllowOriginList=https://*.${DOMAIN}"
|
||||||
@@ -115,12 +114,14 @@ services:
|
|||||||
PGDATA: /pgdata
|
PGDATA: /pgdata
|
||||||
deploy:
|
deploy:
|
||||||
labels:
|
labels:
|
||||||
backupbot.backup: "${ENABLE_BACKUPS:-true}"
|
backupbot.backup: ${ENABLE_BACKUPS:-true}
|
||||||
backupbot.backup.pre-hook: sh -c 'pg_dump -U "$$POSTGRES_USER" -Fc "$$POSTGRES_DB" | gzip > "/postgres.dump.gz"'
|
backupbot.backup.volumes.pgdata.path: "backup.sql"
|
||||||
backupbot.backup.path: "/postgres.dump.gz"
|
backupbot.backup.pre-hook: "/pg_backup.sh backup"
|
||||||
backupbot.backup.post-hook: "rm -f /postgres.dump.gz"
|
backupbot.restore.post-hook: '/pg_backup.sh restore'
|
||||||
backupbot.restore: "true"
|
configs:
|
||||||
backupbot.restore.post-hook: sh -c 'gzip -d /postgres.dump.gz && pg_restore --clean -U "$$POSTGRES_USER" --dbname="$$POSTGRES_DB" < /postgres.dump && rm -f /postgres.dump'
|
- source: pg_backup
|
||||||
|
target: /pg_backup.sh
|
||||||
|
mode: 0555
|
||||||
redis:
|
redis:
|
||||||
image: redis:8.0
|
image: redis:8.0
|
||||||
networks:
|
networks:
|
||||||
@@ -203,6 +204,9 @@ configs:
|
|||||||
entrypoint:
|
entrypoint:
|
||||||
name: ${STACK_NAME}_entrypoint_${LOOMIO_ENTRYPOINT_VERSION}
|
name: ${STACK_NAME}_entrypoint_${LOOMIO_ENTRYPOINT_VERSION}
|
||||||
file: entrypoint.sh
|
file: entrypoint.sh
|
||||||
|
pg_backup:
|
||||||
|
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
|
||||||
|
file: pg_backup.sh
|
||||||
|
|
||||||
secrets:
|
secrets:
|
||||||
devise_secret:
|
devise_secret:
|
||||||
|
|||||||
Executable
+70
@@ -0,0 +1,70 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
BACKUP_PATH="/pgdata"
|
||||||
|
LATEST_BACKUP_FILE="${BACKUP_PATH}/backup.sql"
|
||||||
|
|
||||||
|
function backup {
|
||||||
|
FILE_WITH_DATE="${BACKUP_PATH}/backup_$(date +%F).sql"
|
||||||
|
|
||||||
|
if [ -f "$POSTGRES_PASSWORD_FILE" ]; then
|
||||||
|
export PGPASSWORD=$(cat "$POSTGRES_PASSWORD_FILE")
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Creating backup at ${FILE_WITH_DATE}..."
|
||||||
|
pg_dump -U "${POSTGRES_USER:-postgres}" "${POSTGRES_DB:-postgres}" > "${FILE_WITH_DATE}"
|
||||||
|
|
||||||
|
echo "Copying to ${LATEST_BACKUP_FILE}..."
|
||||||
|
cp -f "${FILE_WITH_DATE}" "${LATEST_BACKUP_FILE}"
|
||||||
|
|
||||||
|
echo "Backup done. You will find it at ${LATEST_BACKUP_FILE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function restore {
|
||||||
|
echo "Restoring database from ${LATEST_BACKUP_FILE}..."
|
||||||
|
|
||||||
|
cd ${BACKUP_PATH}
|
||||||
|
|
||||||
|
function restore_config {
|
||||||
|
echo "Restoring original pg_hba.conf configuration..."
|
||||||
|
cat pg_hba.conf.bak > pg_hba.conf
|
||||||
|
su postgres -c 'pg_ctl reload'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Don't allow any other connections than local
|
||||||
|
echo "Setting up temporary pg_hba.conf to only allow local connections..."
|
||||||
|
cp pg_hba.conf pg_hba.conf.bak
|
||||||
|
echo "local all all trust" > pg_hba.conf
|
||||||
|
su postgres -c 'pg_ctl reload'
|
||||||
|
trap restore_config EXIT INT TERM
|
||||||
|
|
||||||
|
# Recreate Database
|
||||||
|
echo "Dropping existing database ${POSTGRES_DB:-postgres}..."
|
||||||
|
psql -U "${POSTGRES_USER:-postgres}" -d postgres -c "DROP DATABASE \"${POSTGRES_DB:-postgres}\" WITH (FORCE);"
|
||||||
|
|
||||||
|
echo "Creating fresh database ${POSTGRES_DB:-postgres}..."
|
||||||
|
createdb -U "${POSTGRES_USER:-postgres}" "${POSTGRES_DB:-postgres}"
|
||||||
|
|
||||||
|
echo "Restoring data from ${LATEST_BACKUP_FILE}..."
|
||||||
|
psql -U "${POSTGRES_USER:-postgres}" -d "${POSTGRES_DB:-postgres}" -1 -f "${LATEST_BACKUP_FILE}"
|
||||||
|
|
||||||
|
trap - EXIT INT TERM
|
||||||
|
restore_config
|
||||||
|
|
||||||
|
echo "Database restore completed successfully."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Execute the function passed as argument
|
||||||
|
case "$1" in
|
||||||
|
backup)
|
||||||
|
backup
|
||||||
|
;;
|
||||||
|
restore)
|
||||||
|
restore
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {backup|restore}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Backup script improvements contributed by stevensting
|
||||||
Reference in New Issue
Block a user