Skip to content

Commit 35ae106

Browse files
committed
Add task backup_db
1 parent 0896726 commit 35ae106

File tree

4 files changed

+10380
-0
lines changed

4 files changed

+10380
-0
lines changed

Taskfile.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ tasks:
8181
echo ""
8282
echo "===================================================="
8383
84+
backup_db:
85+
desc: Perform a database dump and save it to the host filesystem
86+
cmds:
87+
- |
88+
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
89+
DB_BACKUP_DIR=$(pwd)/db_backups
90+
FILENAME=$DB_BACKUP_DIR/db_backup_$TIMESTAMP.sql
91+
echo "Performing database backup..."
92+
mkdir -p $DB_BACKUP_DIR # Ensure the backup directory exists
93+
DB_USER=$(grep ^DB_USER= .env | cut -d '=' -f 2)
94+
DB_NAME=$(grep ^DB_NAME= .env | cut -d '=' -f 2)
95+
echo "Using database user: $DB_USER and database name: $DB_NAME" # Debugging output
96+
docker compose exec db pg_dump -U $DB_USER $DB_NAME > $FILENAME
97+
if [ $? -eq 0 ]; then
98+
echo "Database backup saved to $FILENAME"
99+
else
100+
echo "Database backup failed. Please check the logs for details."
101+
fi
84102
85103
_show_upgrade_notes:
86104
cmds:

db_backups/db_backup_20250509_100926.sql

Whitespace-only changes.

0 commit comments

Comments
 (0)