Skip to content

Commit 6d5aa0c

Browse files
authored
Merge pull request #261 from Worklenz/development
Development
2 parents f80ec97 + 7618ae7 commit 6d5aa0c

1,161 files changed

Lines changed: 82679 additions & 15470 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backup.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
# Adjust these as needed:
5+
CONTAINER=worklenz_db
6+
DB_NAME=worklenz_db
7+
DB_USER=postgres
8+
BACKUP_DIR=./pg_backups
9+
mkdir -p "$BACKUP_DIR"
10+
11+
timestamp=$(date +%Y-%m-%d_%H-%M-%S)
12+
outfile="${BACKUP_DIR}/${DB_NAME}_${timestamp}.sql"
13+
echo "Creating backup $outfile ..."
14+
15+
docker exec -t "$CONTAINER" pg_dump -U "$DB_USER" -d "$DB_NAME" > "$outfile"
16+
echo "Backup saved to $outfile"

docker-compose.yml

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ services:
8383
POSTGRES_DB: ${DB_NAME:-worklenz_db}
8484
POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
8585
healthcheck:
86-
test: [ "CMD-SHELL", "pg_isready -d ${DB_NAME:-worklenz_db} -U ${DB_USER:-postgres}" ]
86+
test:
87+
[
88+
"CMD-SHELL",
89+
"pg_isready -d ${DB_NAME:-worklenz_db} -U ${DB_USER:-postgres}",
90+
]
8791
interval: 10s
8892
timeout: 5s
8993
retries: 5
@@ -93,23 +97,65 @@ services:
9397
volumes:
9498
- worklenz_postgres_data:/var/lib/postgresql/data
9599
- type: bind
96-
source: ./worklenz-backend/database
97-
target: /docker-entrypoint-initdb.d
100+
source: ./worklenz-backend/database/sql
101+
target: /docker-entrypoint-initdb.d/sql
98102
consistency: cached
103+
- type: bind
104+
source: ./worklenz-backend/database/migrations
105+
target: /docker-entrypoint-initdb.d/migrations
106+
consistency: cached
107+
- type: bind
108+
source: ./worklenz-backend/database/00_init.sh
109+
target: /docker-entrypoint-initdb.d/00_init.sh
110+
consistency: cached
111+
- type: bind
112+
source: ./pg_backups
113+
target: /docker-entrypoint-initdb.d/pg_backups
114+
command: >
115+
bash -c '
116+
if command -v apt-get >/dev/null 2>&1; then
117+
apt-get update && apt-get install -y dos2unix
118+
elif command -v apk >/dev/null 2>&1; then
119+
apk add --no-cache dos2unix
120+
fi
121+
122+
find /docker-entrypoint-initdb.d -type f -name "*.sh" -exec sh -c '"'"'
123+
for f; do
124+
dos2unix "$f" 2>/dev/null || true
125+
chmod +x "$f"
126+
done
127+
'"'"' sh {} +
128+
129+
exec docker-entrypoint.sh postgres
130+
'
131+
db-backup:
132+
image: postgres:15
133+
container_name: worklenz_db_backup
134+
environment:
135+
POSTGRES_USER: ${DB_USER:-postgres}
136+
POSTGRES_DB: ${DB_NAME:-worklenz_db}
137+
POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
138+
depends_on:
139+
db:
140+
condition: service_healthy
141+
volumes:
142+
- ./pg_backups:/pg_backups #host dir for backups files
143+
#setup bassh loop to backup data evey 24h
99144
command: >
100-
bash -c ' if command -v apt-get >/dev/null 2>&1; then
101-
apt-get update && apt-get install -y dos2unix
102-
elif command -v apk >/dev/null 2>&1; then
103-
apk add --no-cache dos2unix
104-
fi && find /docker-entrypoint-initdb.d -type f -name "*.sh" -exec sh -c '\''
105-
dos2unix "{}" 2>/dev/null || true
106-
chmod +x "{}"
107-
'\'' \; && exec docker-entrypoint.sh postgres '
145+
bash -c 'while true; do
146+
sleep 86400;
147+
PGPASSWORD=$$POSTGRES_PASSWORD pg_dump -h worklenz_db -U $$POSTGRES_USER -d $$POSTGRES_DB \
148+
> /pg_backups/worklenz_db_$$(date +%Y-%m-%d_%H-%M-%S).sql;
149+
find /pg_backups -type f -name "*.sql" -mtime +30 -delete;
150+
done'
151+
restart: unless-stopped
152+
networks:
153+
- worklenz
108154

109155
volumes:
110156
worklenz_postgres_data:
111157
worklenz_minio_data:
112-
158+
pgdata:
113159

114160
networks:
115161
worklenz:

0 commit comments

Comments
 (0)