A simple library to make auto backups of PostgreSQL database instances.
There are two ways to install this library:
- Docker
- Directly from sources
-
Clone this repository using
git clone https://github.com/varijkapil13/auto-backup.git
-
Add your database configuration to
server.ini
file.[localhost] url = localhost port = 5432 username = postgres password = password database = testdb
Using this configuration the script will create a folder named
localhost
(taken from the block[localhost]
) and save the backups in that directory with time stampsMore than one database servers can be added to the file. Below is an example configuration for such a setting:
[localhost] url = localhost port = 5432 username = postgres password = password database = testdb [My other server] url = otherserver.com port = 5432 username = postgres password = password database = testdb
Using this configuration the script will create two folders named
localhost
andMy other server
and save the backups in these directories with time stamps. -
Create docker container using
docker build -t vk-auto-backup:latest . && docker run -v /Users/varijkapil13/backups:/app/Backups/ --name vk-auto-backup vk-auto-backup:latest
Replace
/Users/varijkapil13/backups
with path to the folder where you want to store your backups. -
The application is now in a docker container and will automatically backup your databases everyday at 00:00 Hours.
-
Clone this repository using
git clone https://github.com/varijkapil13/auto-backup.git
-
Install virtualenv.
pip install virtualenv
-
Create a virtual environment and activate it.
virtualenv venv
source venv/bin/activate
-
Add your database configuration to
server.ini
file.[localhost] url = localhost port = 5432 username = postgres password = password database = testdb
Using this configuration the script will create a folder named
localhost
(taken from the block[localhost]
) and save the backups in that directory with time stampsMore than one database servers can be added to the file. Below is an example configuration for such a setting:
[localhost] url = localhost port = 5432 username = postgres password = password database = testdb [My other server] url = otherserver.com port = 5432 username = postgres password = password database = testdb
Using this configuration the script will create two folders named
localhost
andMy other server
and save the backups in these directories with time stamps. -
Run the script using:
python3 backup.py
The script will backup your database at 00:00 Hours to folder
.../path/to/app/auto-backup/Backups/
. It will only create the backup once. To make it run automoatically you will have to link the script with some external service linksupervisor.d
or ininit.d
in Ubuntu