INT 21h

Hi, I am Vladimir Smagin, SysAdmin. Telegram Email GIT / GPG / Микроблог

Postgres backup to FTP from Docker or directly, see examples

№ 9473 В разделе "Администрирование" от October 23rd, 2018,

You can easily dump your Postgresql database from Docker container or directly and you have 2 ways to do it. First variant more dangerous, depends on internet connection, but not requires a lot of disk space. Second variant more stable, but if free space suddenly is out your backup will be failed. You can add error checking and reporting to Zabbix like here.

Variant 1: stream backing up file to FTP (directly)

#!/bin/bash
source /etc/profile
weekday=$(date '+%w')
pg_dump postgresql://pguser:pgpassword@mydatabase.server.com:5433/database | gzip | curl -u ftplogin:ftppassword \
ftp://backup-ftp.server.com/postgres-backups/$weekday/db_backup.sql.gz --ftp-create-dirs -T -

Variant 2: dump to local host, upload and delete local file (from Docker)

#!/bin/bash
source /etc/profile

db_user="postgres"
db_pass="lkfgjs4573234"
db_host="127.0.0.1"
db_port="5432"
db_name="my_precious_db"

ftp_user="useruseruser"
ftp_pass="klksdjfa;lkjdf"
ftp_serv="ftp.server.ru"

weekday=$(date '+%w') # 7 days history
history=${weekday}

docker exec -it pg-slave-server su -c "pg_dump postgresql://${db_user}:${db_pass}@${db_host}:${db_port}/${db_name}" \
    postgres |gzip -7 > /tmp/db_backup_${db_name}_${history}.sql.gz
curl --upload-file /tmp/db_backup_${db_name}_${history}.sql.gz ftp://${ftp_user}:${ftp_pass}@${ftp_serv}/
rm -f /tmp/db_backup_${db_name}_${history}.sql.gz

Нет комментариев »

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Микроблог перейти

# 2019-01-05 21:21:04

Надоели мне жадины-говядины из местного НИИ по мониторингу неба, не делятся снимками. Сделал собственный архив снимков с разбивкой по дням tomsk-sky.blindage.org/

# 2019-01-03 15:52:30

Итак, прошло некоторое время после переноса zabbix с mysql на postgres. Нагрузка на сервер значительно упала, заббикс больше не шлет евенты о перегрузе IO. Я доволен результатом, можете смело делать также.


© Vladimir Smagin, 2005-2018. Копирование материалов без разрешения запрещено. GPG DA4CD0F5E222EA727D6A40C413BCE12E5618F071
Яндекс.Метрика

Fortune cookie: There was a young woman named Alice Who peed in a Catholic chalice. She said, "I do this From a great need to piss, And not from sectarian malice."