GithubHelp home page GithubHelp logo

sidbelbase / backup-my-postgres Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 6 KB

Periodically backups postgres databases from EC2 to S3 Bucket using python

Home Page: https://blog.sarojbelbase.com.np/backup-your-postgres-database-like-a-pro

Shell 7.40% Python 92.60%
ec2 postgresql-database s3-bucket backup-script boto3 cronjob dump-database hacktoberfest

backup-my-postgres's Introduction

Backup My Postgres

This project is to backup the database from EC2 Instance to s3 Bucket using python. It automatically dumps PostgreSQL backups to Amazon S3.

Prerequisites

  • Rename .sample.env to .env and add your credentials.
  • Add an AWS account from AWS Console that has the access to the S3 bucket with the following permissions: s3:PutObject
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:PutObject"],
      "Resource": "arn:aws:s3:::<bucket>/<object>/*"
    }
  ]
}
  • Run the following command to create the bucket:
aws s3 mb s3://example-backup-bucket --profile your-profile --region "ap-south-1"

NOTE: run.py is using Asia/Kathmandu Timezone & the database names are hard coded as DATABASES, please modify before running this script.

Usage

  • Install dependencies:

    pip install -r requirements.txt
  • Use python3 to run the script:

    python3 run.py

Cron Job

Setup in EC2 Instance

  • Run the following command to setup the cron job:

    sudo service crond start (if not running)
    crontab -e
  • Use cron to run the script every day at 02:00AM NEPALI TIME (UTC+5:45)

    0 22 * * * python3 /home/ubuntu/backup-my-postgres/run.py

Made with ❤️ in Nepal.

backup-my-postgres's People

Contributors

sarojbelbase avatar

Watchers

 avatar

backup-my-postgres's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.