README
¶
PostgreSQL Backup
Simple system which use pg_dump for dump postgresql db and send info in to Telegram via Horn
Installing
-
Clone project
git clone https://github.com/Rishats/postgresql-backup.git
-
Change folder
cd postgresql-backup
-
Create .env file from .env.example
cp .env.example .env
-
Configure your .env
APP_ENV=production-or-other POSTGRESQL_HOST=127.0.0.1(or-empty-if-localhost) POSTGRESQL_PORT=3306 POSTGRESQL_DB=mydb POSTGRESQL_USER=mydbuser BACKUP_DIR=/var/lib/postgresql/backups INTEGRAM_WEBHOOK_URI=your-uri SENTRY_DSN=your-dsn
Running
Via go native:
Download dependency
go mod download
Build for linux
env GOOS=linux GOARCH=amd64 go build main.go
Creating a Service for Systemd
-
On Ubuntu VPS the following was sufficient to create a service after the go app was placed in home folder: /home/vagrant/mysql-backup
touch /lib/systemd/system/postgresqlbackup.service
-
Inserted the following into the file through vim
vim /lib/systemd/system/postgresqlbackup.service
[Unit] Description=Simple postgresql-backup system written on Go by Rishat Sultanov [Service] Type=simple Restart=always RestartSec=5s User=postgres Group=postgres WorkingDirectory=/var/lib/postgresql/scripts ExecStart=/var/lib/postgresql/scripts/postgresql-backup [Install] WantedBy=multi-user.target
-
This allows you to start your binary/service/postgresqlbackup with:
service postgresqlbackup start
-
To enable it on boot, type: (optional)
service postgresqlbackup enable
-
Don’t forget to check if everything’s cool through: (optional)
service postgresqlbackup status
Example output:
● postgresqlbackup.service - Simple mysql-backup system written on Go by Rishat Sultanov Loaded: loaded (/lib/systemd/system/postgresqlbackup.service; disabled; vendor preset: enabled) Active: active (running) since Sun 2019-06-30 08:58:00 UTC; 1min 30s ago Main PID: 6418 (go_build_main_g) Tasks: 4 Memory: 12.9M CPU: 154ms CGroup: /system.slice/postgresqlbackup.service └─6418 /var/lib/postgresql/scripts/postgresql-backup Jun 30 08:58:00 homestead systemd[1]: postgresqlbackup.service: Service hold-off time over, scheduling restart. Jun 30 08:58:00 homestead systemd[1]: Stopped Simple mysql-backup system written on Go by Rishat Sultanov. Jun 30 08:58:00 homestead systemd[1]: Started Simple mysql-backup system written on Go by Rishat Sultanov. Jun 30 08:58:00 homestead go_build_main_go_linux[6418]: Output: 0 Jun 30 08:58:01 homestead go_build_main_go_linux[6418]: &{200 OK 200 HTTP/2.0 2 0 map[Content-Length:[0] Content-Type:[text/plain; charset=utf-8] Date:[Su Jun 30 08:58:01 homestead go_build_main_go_linux[6418]: 2019-07-01 02:00:00 +0000 UTC
Via docker:
docker build --target=build-env -t postgresql-backup .
docker run -d --name "postgresql-backup" postgresql-backup
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Rishat Sultanov - Rishats
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Documentation
¶
There is no documentation for this package.