Skip to content

About

A Bash script that facilitates the creation of database backups in a Docker PostgreSQL container.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Database Backup Generator

This script generates backups of all databases in a PostgreSQL Docker container and saves them in a folder in the host machine.

Comments/Improvements

  • A script should be created to delete certain old backups from time to time so that the available space does not fill up
  • Could work with more database systems than just PostgreSQL

Requirements

  • Docker *
  • A Docker container with a PostgreSQL image *
  • Docker with sudo permissions *

How to use

Setup

  1. Clone this repository
  2. Copy the file database_backup_generator.sh to your host machine
  3. Give execution permissions to the file
chmod +x database_backup_generator.sh

Default configuration

  1. Run the script
./database_backup_generator.sh

Custom configuration

  1. You can run the script with the following parameters:
  • -t: Run interactive mode
  • --container-name <container_name>: The name of the container with the PostgreSQL image
  • --username <username>: The username of the PostgreSQL user
  • --backup-directory <path>: The path of the folder where the backups will be saved
  • --default-dbs: If this flag is set, the script will generate backups of the default databases (postgres, template0, template1)

Example:

./database_backup_generator.sh --container-name my_postgres_container --username my_user --backup-directory /tmp/backups --default-dbs

Crontab

  1. You can add the script to your crontab file to run it automatically.
crontab -e
  1. For example, if you want to run the script every Sunday at 00:00, you can add the following line to your crontab file (replace the paths with your own):
0 0 * * 0 /database_backup_generator.sh >> /tmp/backups/database_backup_generator.log 2>&1

(The script will generate a log file in the path /tmp/backups/database_backup_generator.log)

About

A Bash script that facilitates the creation of database backups in a Docker PostgreSQL container.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages