INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / RSS / GPG

Postgres backup to FTP from Docker or directly, see examples

№ 9473 В разделе Sysadmin от 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

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

Compress and copy files through ssh, convenient for simple backups

№ 9402 В разделе Sysadmin от September 10th, 2018,
В подшивках: ,

tar zcvf - http.access.log.1 |ssh -i temp.key root@server.ru "cat >/tmp/http.access.log.1.tgz"

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

Образ диска с помощью dd со сжатием на лету

№ 8232 В разделе Sysadmin от November 16th, 2016,
В подшивках: ,

Чтобы сделать полный бэкап жесткого диска

dd if=/dev/sda bs=2M | gzip -c > /media/backups/diskimages/sda_full.image.gz

В обратную сторону

gunzip -c /media/backups/diskimages/sda_full.image.gz | dd of=/dev/sda bs=2M

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

Быстро делаем бэкап с помощью Duplicity

№ 7909. В разделе Sysadmin от January 2nd, 2016

В подшивках: ,

Яндекс.Метрика

Fortune cookie: There once was a gangster named Brown -- the sneakiest bastard in town. He was caught by G-men Shooting his semen Where the cops would slip and fall down.