mer. 19 août 2026 13:18:09 CEST
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
FROM alpine:latest
|
||||
RUN apk add --no-cache postgresql16-client bash
|
||||
COPY root /
|
||||
RUN chmod +x /*.sh
|
||||
EXPOSE 80
|
||||
WORKDIR /backup
|
||||
VOLUME [ "/backup" ]
|
||||
CMD ["/run.sh"]
|
||||
@@ -0,0 +1,13 @@
|
||||
Example docker-compose.yml file
|
||||
```
|
||||
services:
|
||||
backup:
|
||||
image: ghcr.io/emilch/postgresql-container-backup:main
|
||||
restart: always
|
||||
volumes:
|
||||
- ./backup:/backup
|
||||
environment:
|
||||
PGSQL_USER: postgres
|
||||
PGSQL_PASS: postgrespassword
|
||||
PGSQL_HOST: postgresdb
|
||||
```
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
export TAG=16-$(date '+%s')
|
||||
docker compose build --push
|
||||
echo "The tag to use is: 16-$TAG"
|
||||
@@ -0,0 +1,4 @@
|
||||
services:
|
||||
ttrss:
|
||||
build: ./
|
||||
image: registry.cheriches.eu/pgsql-backup:16-${TAG}
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Postgres configuration (replace with your details)
|
||||
PGUSER="your_username"
|
||||
PGHOST="your_hostname"
|
||||
PGPORT="5432"
|
||||
export PGPASSWORD="your_password"
|
||||
BACKUPDIR="/backup"
|
||||
EXCLUDE_DBS="template0 template1 postgres" # Exclude these databases
|
||||
|
||||
# Get date in YYYY-MM-DD format
|
||||
CURRENTDATE=$(date +%Y-%m-%d)
|
||||
|
||||
# Function to backup a single database
|
||||
backup_database() {
|
||||
local db_name="$1"
|
||||
local backup_file="$BACKUPDIR/$CURRENTDATE-$db_name.sql.gz"
|
||||
|
||||
# Skip excluded databases
|
||||
if [[ "$EXCLUDE_DBS" =~ " $db_name " ]]; then
|
||||
echo "Skipping excluded database: $db_name"
|
||||
return
|
||||
fi
|
||||
|
||||
# Dump the database
|
||||
pg_dump -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" "$db_name" | gzip > "$backup_file"
|
||||
echo "Backup completed: $backup_file"
|
||||
}
|
||||
|
||||
# Ensure backup directory exists
|
||||
mkdir -p "$BACKUPDIR"
|
||||
|
||||
# Get list of databases (excluding template and postgres)
|
||||
databases=$(psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;")
|
||||
|
||||
# Loop through databases and backup each one
|
||||
for db_name in $databases; do
|
||||
backup_database "$db_name"
|
||||
done
|
||||
|
||||
# Delete backups older than 60 days
|
||||
find "$BACKUPDIR" -type f -name "*.sql.gz" -mtime +30 -delete
|
||||
|
||||
echo "Deleted old backups from $BACKUPDIR"
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
sed -i -e "s#your_username#$PGSQL_USER#" \
|
||||
-e "s#your_password#$PGSQL_PASS#" \
|
||||
-e "s#your_hostname#$PGSQL_HOST#" \
|
||||
/backup.sh
|
||||
|
||||
while true;
|
||||
do
|
||||
/backup.sh
|
||||
sleep 172800;
|
||||
done
|
||||
Reference in New Issue
Block a user