This backup restore bot can backup/restore a database and upload/download the backup file to/from a remote storage engine
Project description
DataBaseBackupRestoreOnK8s
Project Introduction
If you have data that you want to import or export from a database that you deployed in a k8s cluster, you need to install a database client, create a dump file, then upload the dump file somewhere else.
This project will help you to avoid all that. The only thing you need to do is to provide the name of the database and where you want to upload/download the backup file.
Features
- Create database backup file
- Upload backup file to remote storage
- Download backup file from remote storage
- Restore/Populate database
- Provide k8s cron job to create backup with configurable time interval
- If you use auto backup/restore feature in the cronjob/job, the restore job will always find the latest backup of the target database to do restore.
- List available database that can be backed up.
- List available backup that can be used to restore
Usage
There are different ways to use this project.
- Use this project as a python package
- Use this project as a python Command Line Interface
- Use this project as a k8s cronjob/job
Use this project as a python package
Use this project as a python Command Line Interface
Note, if you use remote storage such as s3 (or minio), you need to set up your s3 creds correctly in your env variables.
git clone https://github.com/pengfei99/K8sCronJobPostgresBackup.git
cd K8sCronJobPostgresBackup
# show the command line options and comments
python dbsavior/main.py -h
# list existing backup
python dbsavior/main.py --db_type postgres --storage_type s3 --action list_backups --backup_dir s3://path/to/sql_backup
# list existing database
python dbsavior/main.py --db_type postgres --storage_type s3 --action list_dbs --db_login user-pengfei --db_pwd changeMe --db_host 127.0.0.1 --db_port 5432
# auto backup
python dbsavior/main.py --db_type postgres --storage_type s3 --action auto_backup --db_login user-pengfei --db_pwd changeMe --db_host 127.0.0.1 --backup_dir s3://path/to/sql_backup --target_db test
# auto restore
python dbsavior/main.py --db_type postgres --storage_type s3 --action auto_restore --db_login user-pengfei --db_pwd changeMe --db_host 127.0.0.1 --backup_dir s3://path/to/sql_backup --target_db test
# populate a database with a sql dump
python dbsavior/main.py --db_type postgres --storage_type s3 --action populate --db_login user-pengfei --db_pwd changeMe --db_host 127.0.0.1 --backup_file s3://path/to/sql_backup/2022-01-12_test_pg_bck.sql --target_db test
Use this project as a k8s cronjob/job
For the job and cronjob is set up for s3 and postgresql. You need to add your s3 and postgresql server credentials into the yaml file to run the job and cronjob correctly.
git clone https://github.com/pengfei99/K8sCronJobPostgresBackup.git
cd K8sCronJobPostgresBackup/k8s
# this job calls auto backup on a database once
kubectl apply -f job_backup.yaml
# this cronjob calls auto backup on a database based on the cron. The default cron starts at mid night every day
kubectl apply -f cronjob_backup.yaml
# this job calls auto restore of a database, if it finds many available backups, it will apply the latest one
kubeclt apply -f job_restore.yaml
# this job populate a database with a specific backup file.
kubectl apply -f job_populate.yaml
Future works
For now, this project only implements the postgres server for the DbManagerInterface. For the StorageEngineInterface, we only implement the s3 and local filesystem(tested for linux). If you want to back up a database in a mysql server and store the backup on HDFS, you only need to implement the DbManagerInterface and StorageEngineInterface. The rest of the project can be reused automatically.
Other docs that may be useful for you
If you are not familiar with postgresql backup and restore procedure. Please visit this doc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dbsavior-0.1.0.tar.gz
.
File metadata
- Download URL: dbsavior-0.1.0.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.8.10 Linux/5.11.0-46-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eb6ba62fd96ba829845e9ebd5219dced1bf658c56252c624a920c0b95e4c18f |
|
MD5 | c7727bf0c83268b9d3ed4599a305ed59 |
|
BLAKE2b-256 | 54d0ee07069c8f3e843e5ec2bba7fdc1a34dccded7eb99a6a13eefa583516ab5 |
File details
Details for the file dbsavior-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: dbsavior-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.8.10 Linux/5.11.0-46-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f50cfef1f3914f94cc249f6deda2c722fe2d15e51d8d298307132c68246eba2d |
|
MD5 | e89911bb4bac4d1bec6f3977780dd190 |
|
BLAKE2b-256 | dae1d129022709ce63c4098f40ec84f03d7aa54eac07540f226eb40bf2095353 |