2024-11-06 19:02:44 +00:00
|
|
|
# Usage
|
|
|
|
|
|
|
|
## Authentication
|
|
|
|
|
|
|
|
Do not forget to create and/or edit `~/.pgpass` file providing all needed passwords for each host:
|
|
|
|
|
|
|
|
The format is the following:
|
2024-11-06 19:09:08 +00:00
|
|
|
```properties
|
2024-11-06 19:02:44 +00:00
|
|
|
hostname:port:database:username:password
|
|
|
|
```
|
|
|
|
|
|
|
|
Example
|
|
|
|
|
2024-11-06 19:09:08 +00:00
|
|
|
```properties
|
2024-11-06 19:02:44 +00:00
|
|
|
localhost:5432:*:postgres:pg_password_1
|
|
|
|
localhost:5433:*:postgres:pg_password_2
|
2024-11-06 20:33:37 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Scheduling
|
|
|
|
|
|
|
|
### Systemd
|
|
|
|
|
|
|
|
#### Service
|
|
|
|
|
|
|
|
`/etc/systemd/system/postgresql_backup.service`
|
|
|
|
|
|
|
|
```ini
|
|
|
|
[Unit]
|
|
|
|
Description=PostgreSQL backup Script
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=oneshot
|
|
|
|
WorkingDirectory=/root/scripts/postgresql_backup
|
|
|
|
ExecStart=/root/scripts/postgresql_backup/pg_backup.sh
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Timer
|
|
|
|
|
|
|
|
`/etc/systemd/system/postgresql_backup.timer`
|
|
|
|
|
|
|
|
```ini
|
|
|
|
[Unit]
|
|
|
|
Description=Run Backup Script Every Night
|
|
|
|
|
|
|
|
[Timer]
|
|
|
|
OnCalendar=*-*-* 22:00:00
|
|
|
|
Unit=postgresql_backup.service
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=timers.target
|
|
|
|
```
|
|
|
|
|
|
|
|
Then:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
systemctl enable postgresql_backup.timer --now
|
2024-11-06 19:02:44 +00:00
|
|
|
```
|