Skip to content

Commit 2649a4e

Browse files
committed
backup data
1 parent 31982b3 commit 2649a4e

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ data/screenshots
1111
data/typesense-data
1212
# Allow for this director to be created
1313
data/uploads/profile-pictures/*.png
14+
data/backups
1415

1516
### STS ###
1617
.apt_generated

deploy/backup.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
ORIGIN_PATH=$(pwd)
3+
# Navigate to the script directory
4+
cd $(dirname "$0")
5+
if [ $# -eq 0 ]; then
6+
echo "No Env file provided, using default."
7+
. ../.env
8+
else
9+
. $ORIGIN_PATH/$1
10+
fi
11+
12+
mkdir -p ../data/backups
13+
14+
# Variables
15+
BACKUP_DIR=../data/backups
16+
DB_NAME=$POSTGRES_DB
17+
DB_USER=$POSTGRES_USER
18+
DB_PASSWORD=$POSTGRES_PASSWORD
19+
CONTAINER_NAME=findfirst-db-1
20+
21+
# Get current date and time for backup file
22+
TIMESTAMP=$(date +"%F_%T")
23+
BACKUP_FILE=$BACKUP_DIR/backup_$DB_NAME_$TIMESTAMP.sql
24+
25+
oldBackup=$(ls $BACKUP_DIR/*.sql)
26+
27+
# Run pg_dump inside the PostgreSQL container
28+
docker exec -t $CONTAINER_NAME pg_dump -U $DB_USER $DB_NAME >$BACKUP_FILE
29+
30+
rm $oldBackup
31+
32+
echo "Backup completed: $BACKUP_FILE"

deploy/deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/sh
22
# Intended to be run from the project root directory.
33
cd $(dirname "$0")
4+
./backup.sh ../.env
45
cd ..
56

67
git pull

0 commit comments

Comments
 (0)