INT 21h

Hi, I am Vladimir Smagin, SysAdmin, DevOps and barely good guy. 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-03-18 13:39:04

Yes, Solus is beautiful, but what you can't do:
1) set your password to 123, OS thinks you are stupid
2) set any other keyboard layout switch hotkey instead of fucking macos style, no choice

# 2019-02-14 13:07:54

есть у нас один деплойный плейбук сразу кучи проектов на кучу наших серверов и клиентов. хз что за демоны в голове сношались у человека, который его придумал.

# 2019-02-14 08:46:15

logstash не получится балансировать в кубере, filebeat держит соединение с логсташем постоянно, не разрывая соединение из-за чего будет работать только 1 под из всех поднятых.


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

Fortune cookie: There was an old man from Bengal Who liked to do tricks in the hall. His favorite trick Was to stand on his dick While he rolled around on one ball.