Skip to content

Database

Czechbol edited this page Feb 26, 2021 · 5 revisions

The Docker containers are linux boxes, which means that you can open shell inside of them:

docker exec -it amadeus_db_1 sh

To connect to the database, run

# docker (shell is already opened)
psql -U postgres -p 5432
# docker
docker exec -it amadeus_db_1 psql -U postgres -p 5432
# standalone
psql

Once the psql shell is ready, you can display all databases with \l, all tables with \dt and use standard SQL queries like SELECT * FROM users.

Backups

Please note that migration between docker and standalone installation is possible, but requires some manual editing of the dump file:

  • Cut down database operations
  • Rename database (postgres to amadeus)
  • DROP all existing tables You should have at least basic knowledge of SQL before you do this.

Docker

# backup
docker exec -it amadeus_db_1 pg_dumpall -c -U postgres > "~/backups/dump_`date +%Y-%m-%d"_"%H-%M-%S`.sql"
# restore
docker-compose down
docker start amadeus_db_1
cat dump.sql | docker exec -i amadeus_db_1 psql -U postgres
docker stop amadeus_db_1

Standalone

# backup
pg_dump amadeus > "~/backups/dump_`date +%Y-%m-%d"_"%H:%M:%S`.sql"
# restore
cat dump.sql | psql

Automatic backups

Amadeus provides a helper script for both hosting options. You can set up a cron job to do the backup (every day at 5AM in this example) with crontab -e:

# docker
0 5 * * * bash ~/amadeus/resources/backup.docker.sh     >> ~/backup.log 2>&1
# standalone
0 5 * * * bash ~/amadeus/resources/backup.standalone.sh >> ~/backup.log 2>&1

Make sure that the script has executable bit setup. (chmod +x resources/backup._.sh)

Note: The database and IS NOT encrypted. It is up to you to comply with the GDPR rules: limiting access to the server and/or encrypting.