# Backup Postgres Database
[![Downloads](https://static.pepy.tech/personalized-badge/postgres-backup?period=month&units=none&left_color=grey&right_color=blue&left_text=Downloads)](https://pepy.tech/project/postgres-backup) ![Version](https://img.shields.io/badge/version-0.1.1-blue) ![Python-Version](https://img.shields.io/badge/python-3.9-blue) ![issues](https://img.shields.io/github/issues/Nil-Andreu/postgres-backup) ![PyPI - Status](https://img.shields.io/pypi/status/postgres-backup) ![License](https://img.shields.io/github/license/Nil-Andreu/postgres-backup)
## Basic Usage
This simple Python package allows you to create easily the database backup of Postgres databases.
You can upload them to cloud storage buckets by creating a cron job.
```python
from postgres_backup import Backup
# Instantiate the backup object with Postgres database_uri
backup = Backup()
# Create the file for backup
backup.create()
```
You should have as environment variable `DATABASE_URL`, which is the URI of the Postgres database.
This URI has the following structure: `db:engine:[//[user[:password]@][host][:port]/][dbname]`.
Can also specify a list of the tables for which you want to create the backup:
```python
backup.create(table_names=['table1', 'table2', ...]
```
## Why?
This package has proved experience of working well for databases of small-mid size.
Doing this, you make sure you can store your database backups without relying in only one cloud provider or region.
## Bucket Storage
Have provided the ability to store those backups in cloud buckets.
### Google Cloud Storage
For using this functionality, you need to install the dependencies needed of the package:
```bash
pip3 install "postgres-backup[gcs]"
```
This basically will install also the `google` package.
And then after we have the backup created, we would keep following with:
```python
# Upload it to google cloud storage
backup.upload(
provider=CloudProviders.gcs.value,
)
```
Where the `google_cloud_certification` is a dictionary, with the key-values of the client api keys:
```python
google_cloud_credentials = {
"type": "service_account",
"project_id": "xxx-saas",
"private_key_id": "xxxxxxxx",
"private_key": "-----BEGIN PRIVATE KEY-----\nxxxxxxxxxx\n-----END PRIVATE KEY-----\n",
"client_email": "xxx@xxx-saas.iam.gserviceaccount.com",
"client_id": "xxx",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/xxx%xxx-saas.iam.gserviceaccount.com"
}
```
Recommended to provide each key as an environmental variable:
- GOOGLE_CLOUD_TYPE -> type
- GOOGLE_CLOUD_PROJECT_ID -> project_id
- GOOGLE_CLOUD_PRIVATE_KEY_ID -> private_key_id
- GOOGLE_CLOUD_PRIVATE_KEY -> private_key
- GOOGLE_CLOUD_CLIENT_EMAIL -> client_email
- GOOGLE_CLOUD_CLIENT_ID -> client_id
- GOOGLE_CLOUD_AUTH_URI -> auth_uri
- GOOGLE_CLOUD_TOKEN_URI -> token_uri
- GOOGLE_CLOUD_AUTH_PROVIDER_X509_CERT_URL -> auth_provider_x509_cert_url
- GOOGLE_CLOUD_CLIENT_X509_CERT_URL -> client_x509_cert_url
Moreover `PROJECT_NAME` and `BUCKET_NAME` of the google bucket, and finally `DATABASE_URL` of Postgres database.
In the case that we do not have a bucket already created for storing the backups, we could add additional parameters to create it:
```python
from postgres_backup.schemas import CloudStorageType, CloudProviders
backup.upload(
provider=CloudProviders.gcs.value,
bucket_name=bucket_name,
create_bucket=True,
storage_class=CloudStorageType.NEARLINE.value
)
```
### Amazon Web Services
For uploading into AWS after having created the backup, you need first to install the optional dependencies:
```bash
pip3 install "postgres-backup[aws]"
```
After that, you can use the method of `upload` of the Backup as:
```python
# Upload it to aws storage
backup.upload(
provider=CloudProviders.aws.value,
)
```
It requires you to have as environmental variables `AWS_SERVER_PUBLIC_KEY`, `AWS_SERVER_PRIVATE_KEY` and `REGION_NAME`.
Raw data
{
"_id": null,
"home_page": "https://github.com/Nil-Andreu/postgres-backup",
"name": "postgres-backup",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "backup,Postgres,SQL,database,PostgreSQL,Data Engineering",
"author": "Nil Andreu",
"author_email": "nilandreug@email.com",
"download_url": "https://files.pythonhosted.org/packages/54/78/140ad5ad8d92ebe43fa09566e56d0fadd5d32c2eb52f47edeaed932b7ff8/postgres-backup-0.3.3.tar.gz",
"platform": null,
"description": "# Backup Postgres Database\n\n\n[![Downloads](https://static.pepy.tech/personalized-badge/postgres-backup?period=month&units=none&left_color=grey&right_color=blue&left_text=Downloads)](https://pepy.tech/project/postgres-backup) ![Version](https://img.shields.io/badge/version-0.1.1-blue) ![Python-Version](https://img.shields.io/badge/python-3.9-blue) ![issues](https://img.shields.io/github/issues/Nil-Andreu/postgres-backup) ![PyPI - Status](https://img.shields.io/pypi/status/postgres-backup) ![License](https://img.shields.io/github/license/Nil-Andreu/postgres-backup)\n\n\n## Basic Usage\n\nThis simple Python package allows you to create easily the database backup of Postgres databases.\nYou can upload them to cloud storage buckets by creating a cron job.\n\n```python\n from postgres_backup import Backup\n\n # Instantiate the backup object with Postgres database_uri\n backup = Backup()\n\n # Create the file for backup\n backup.create()\n```\n\nYou should have as environment variable `DATABASE_URL`, which is the URI of the Postgres database.\nThis URI has the following structure: `db:engine:[//[user[:password]@][host][:port]/][dbname]`.\n\nCan also specify a list of the tables for which you want to create the backup:\n```python\n backup.create(table_names=['table1', 'table2', ...]\n```\n\n## Why?\n\nThis package has proved experience of working well for databases of small-mid size.\n\nDoing this, you make sure you can store your database backups without relying in only one cloud provider or region.\n\n## Bucket Storage\n\nHave provided the ability to store those backups in cloud buckets.\n\n### Google Cloud Storage\n\nFor using this functionality, you need to install the dependencies needed of the package:\n\n```bash\n pip3 install \"postgres-backup[gcs]\"\n```\nThis basically will install also the `google` package.\n\nAnd then after we have the backup created, we would keep following with:\n```python\n # Upload it to google cloud storage\n backup.upload(\n provider=CloudProviders.gcs.value,\n )\n```\n\nWhere the `google_cloud_certification` is a dictionary, with the key-values of the client api keys:\n```python\n google_cloud_credentials = {\n \"type\": \"service_account\",\n \"project_id\": \"xxx-saas\",\n \"private_key_id\": \"xxxxxxxx\",\n \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nxxxxxxxxxx\\n-----END PRIVATE KEY-----\\n\",\n \"client_email\": \"xxx@xxx-saas.iam.gserviceaccount.com\",\n \"client_id\": \"xxx\",\n \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n \"token_uri\": \"https://oauth2.googleapis.com/token\",\n \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\n \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/xxx%xxx-saas.iam.gserviceaccount.com\"\n }\n```\n\nRecommended to provide each key as an environmental variable:\n- GOOGLE_CLOUD_TYPE -> type\n- GOOGLE_CLOUD_PROJECT_ID -> project_id\n- GOOGLE_CLOUD_PRIVATE_KEY_ID -> private_key_id\n- GOOGLE_CLOUD_PRIVATE_KEY -> private_key\n- GOOGLE_CLOUD_CLIENT_EMAIL -> client_email\n- GOOGLE_CLOUD_CLIENT_ID -> client_id\n- GOOGLE_CLOUD_AUTH_URI -> auth_uri\n- GOOGLE_CLOUD_TOKEN_URI -> token_uri\n- GOOGLE_CLOUD_AUTH_PROVIDER_X509_CERT_URL -> auth_provider_x509_cert_url\n- GOOGLE_CLOUD_CLIENT_X509_CERT_URL -> client_x509_cert_url\n\nMoreover `PROJECT_NAME` and `BUCKET_NAME` of the google bucket, and finally `DATABASE_URL` of Postgres database.\n\n\nIn the case that we do not have a bucket already created for storing the backups, we could add additional parameters to create it:\n```python\n from postgres_backup.schemas import CloudStorageType, CloudProviders\n\n backup.upload(\n provider=CloudProviders.gcs.value,\n bucket_name=bucket_name,\n create_bucket=True,\n storage_class=CloudStorageType.NEARLINE.value\n )\n```\n\n\n### Amazon Web Services\n\nFor uploading into AWS after having created the backup, you need first to install the optional dependencies:\n\n```bash\n pip3 install \"postgres-backup[aws]\"\n```\n\nAfter that, you can use the method of `upload` of the Backup as:\n\n```python\n # Upload it to aws storage\n backup.upload(\n provider=CloudProviders.aws.value,\n )\n```\n\nIt requires you to have as environmental variables `AWS_SERVER_PUBLIC_KEY`, `AWS_SERVER_PRIVATE_KEY` and `REGION_NAME`.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Automation of the creation of backups of Postgres databases",
"version": "0.3.3",
"split_keywords": [
"backup",
"postgres",
"sql",
"database",
"postgresql",
"data engineering"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "64717e44c46d7d543c51a9aab1ef9d68e1005c69aae65581c29453ebf33372cf",
"md5": "fbc5fc26d6710c9f4d96e5ef5f169301",
"sha256": "4b7c8f041e26713943383eb618abdf97844fa31d793f0271b76d6b78862f98aa"
},
"downloads": -1,
"filename": "postgres_backup-0.3.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fbc5fc26d6710c9f4d96e5ef5f169301",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 11896,
"upload_time": "2023-01-26T16:03:48",
"upload_time_iso_8601": "2023-01-26T16:03:48.791119Z",
"url": "https://files.pythonhosted.org/packages/64/71/7e44c46d7d543c51a9aab1ef9d68e1005c69aae65581c29453ebf33372cf/postgres_backup-0.3.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5478140ad5ad8d92ebe43fa09566e56d0fadd5d32c2eb52f47edeaed932b7ff8",
"md5": "a914ea718b9ea2afad88c9d502f16cf3",
"sha256": "79b15a81cd14dd7710962810c84b153ef8888c900cc2aa6de9e01e58dd006523"
},
"downloads": -1,
"filename": "postgres-backup-0.3.3.tar.gz",
"has_sig": false,
"md5_digest": "a914ea718b9ea2afad88c9d502f16cf3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10332,
"upload_time": "2023-01-26T16:03:50",
"upload_time_iso_8601": "2023-01-26T16:03:50.672554Z",
"url": "https://files.pythonhosted.org/packages/54/78/140ad5ad8d92ebe43fa09566e56d0fadd5d32c2eb52f47edeaed932b7ff8/postgres-backup-0.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-26 16:03:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Nil-Andreu",
"github_project": "postgres-backup",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "pydantic",
"specs": [
[
"==",
"1.10.4"
]
]
},
{
"name": "sh",
"specs": []
}
],
"lcname": "postgres-backup"
}