|
|
THIS PAGE IS WORK IN PROGRES
|
|
|
|
|
|
# Install on Ubuntu 20.*
|
|
|
|
|
|
```bash
|
|
|
sudo apt update
|
|
|
sudo apt install postgresql postgresql-contrib
|
|
|
sudo systemctl start postgresql.service
|
|
|
```
|
|
|
|
|
|
Check status: `sudo systemctl status postgresql.service`
|
|
|
|
|
|
See [this tutorial](https://www.digitalocean.com/community/tutorials/how-to-install-postgresql-on-ubuntu-20-04-quickstart) for more info.
|
|
|
|
|
|
# Connect to DB
|
|
|
|
|
|
```bash
|
|
|
sudo -u postgres psql # to open psql (the interactive command line interface to the DB)
|
|
|
\l # to list all DB's
|
|
|
\c <name of DB> # to connect to one DB
|
|
|
\d # to describe all in that DB
|
|
|
|
|
|
```
|
|
|
|
|
|
# Backup restore
|
|
|
|
|
|
## Daily backup
|
|
|
|
|
|
From memory (so untested):
|
|
|
|
|
|
1. In de container commando `crontab -e`
|
|
|
2. en dan een crontabje om iedere nacht om 0:00 te draaien:
|
|
|
|
|
|
```crontab
|
|
|
0 0 * * * /srv/dewilde/backupscript.sh
|
|
|
```
|
|
|
|
|
|
A script is necessary because many things (such as using a pipe on your backup command) is not possible directly from a crontab line.
|
|
|
|
|
|
3. Create the backupscript.sh with this content and make it executable:
|
|
|
|
|
|
```bash
|
|
|
pg_dump dewilde_db_name > /path/to/backup/location/dewilde_backup_$(date +%A)
|
|
|
```
|
|
|
|
|
|
This will create a postgres backup file that ends with the name of the weekday it was taken. E.g. `dewilde_backup_Monday`. If it runs again on Monday it will overwrite the existing one.
|
|
|
|
|
|
The `/path/to/backup/location` is a mount to a container volume the is accessible from outside the container. On there it could even be a mount to an external drive, cloud service. I tested it with StackStorage WebDAV but it should work similar for any file storage solution (e.g. Contabo's S3 😉?).
|
|
|
|
|
|
## Restore
|
|
|
|
|
|
The restore can be done with command `pg_restore`. For instance
|
|
|
|
|
|
```bash
|
|
|
pg_restore dewilde_backup_Monday
|
|
|
```
|
|
|
|
|
|
|
|
|
\ No newline at end of file |