Skip to content

In this repository, there is a script that will automatically back up the databases in your PostgreSQL cluster structure.

Notifications You must be signed in to change notification settings

koraykutanoglu/postgresql-cluster-databases-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Backing Up Databases in PostgreSQL Cluster

It provides a script to backup databases in PostgreSQL cluster structure in this repository.

Working Steps

  1. First, edit the script file.
nano script.sh
  1. You need to set the variables in the script file according to yourself. First, set the IP address of the backup server.
sftp_ip=10.10.10.xx
  1. Enter the name of the user to connect to the backup server
sftp_user=root
  1. Enter the port to make the SFTP connection
sftp_port=22
  1. backups need to be taken in the local directory first. Specify the local directory where backups will be taken.
local_backup_directory=/my/backupdir
  1. Where to back up files on the SFTP server. Attention! The contents of this specified directory should be reserved for backup files only. There should be no directories such as /root /etc. rm -rf is used when deleting historical files.
sftp_backup_directory=/root/backup
  1. Enter the IP number in the last digit of your KeepAlived IP address. For example, if your keepalived IP address is 10.10.10.10, you should enter 10.
keepalivedip=xx
  1. How many days the backups will be maintained on the SFTP server.
backup_time=5
  1. Backups are sent encrypted. That's why you need a password to be able to open backups again. Passwords are encrypted with GPG.
file_password=password

To be able to turn the backups back on, use the command below

gpg --output test.sql.gz --decrypt test.sql.gz.gpg
  1. ssh-key must be set for machines to access each other. This is how the backup is sent. ssh-key should be copied from all postgresql servers to SFTP server.
ssh-keygen
ssh-copy-id -f user@hostname

Finally;

After all these settings, install this script file on all your postgresql cluster machines and create a cron for this file on each machine.

For example, let's say I run a cron at 1 o'clock every night. At 1 o'clock all the script files will run and the script file will check the IP address of each machine. The machine with the KeepAlived IP will run the script.

After the backup is received in the local directory and sent to the SFTP server, the backups will be deleted from the local directory.

In addition, historical backups will be kept on the SFTP server for the specified date.

Script Screenshot

Ekran Resmi 2022-01-15 14 27 04

About

In this repository, there is a script that will automatically back up the databases in your PostgreSQL cluster structure.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages