-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.sh
42 lines (32 loc) · 1.08 KB
/
db.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
source .env
container="memgpt-postgres"
echo ""
if [[ -z "$(docker ps --filter name=$container --format "{{.Names}}" | grep $container)" ]]; then
echo "To interact with the DB, please start the environment using:"
echo "> ./start.sh"
echo ""
exit 1
fi
if [[ $1 == "dump" ]]; then
dump_name=${2-memgpt}
docker exec $container pg_dump -U $POSTGRES_USER -d $POSTGRES_DB > ./config/database/"${dump_name}.sql"
exit_status=$?
if [[ $exit_status -eq 0 ]]; then
echo "✔︎ Dumped the current DB to the 'content' folder ..."
else
echo "✘︎ There was an error while creating the DB dump ..."
fi
elif [[ $1 == "restore" ]]; then
dump_name=${2-memgpt}
cat ./config/database/"${dump_name}.sql" | docker exec -i $container psql -U $POSTGRES_USER -d $POSTGRES_DB
exit_status=$?
if [[ $exit_status -eq 0 ]]; then
echo "✔︎ Restored the DB dump from the 'content' folder ..."
else
echo "✘︎ There was an error while restoring the DB dump ..."
fi
else
echo "Invalid argument. Please choose either 'dump' or 'restore'."
fi
echo ""