-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example of config file has been created, and also a requirements file.
- Loading branch information
1 parent
38fe122
commit cdf6fcc
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## Introduction | ||
This is a simple Python script to back up databases. | ||
Right now, it only backs up MySQL databases, but _'maybe maybe'_ in the future | ||
we might want to extend to RPM and Postgres as well. | ||
|
||
## How it works | ||
It is **assumed** that a configuration file `/etc/dbbackupr2.conf` exists. | ||
An example of the file can be found in this repo as `dbbackupr2.conf` | ||
|
||
The script makes a list of all databases existing on the MySQL host, does a | ||
`mysqldump` per database, and then makes it into a bzip2 archive, to save space. | ||
The resulting files, that look like `myql-my_database-2024-07-09.bz2`, | ||
are stored in `BACKUP_DIR`. | ||
|
||
Old database backups are retained for `MYSQL_KEEP_DAYS` days. | ||
|
||
It is **assumed** that `mysqldump` and `bzip2` are available on the sytem. | ||
No checks are done, so the script simply raises a gory Exception when | ||
these CLI tools cannot be found. | ||
|
||
It is also **assumed** that the MySQL connnection has already been defined | ||
via the file ~/.my.cnf: | ||
```ini | ||
[client] | ||
host=<mysql hostname> | ||
user=<mysql username> | ||
password=<mysql password> | ||
default-character-set = utf8mb4 | ||
``` | ||
|
||
## Builds | ||
This script is being built into a binary with the help of [pyinstaller](https://pyinstaller.org/en/stable/), | ||
|
||
Running pyinstaller, when a `.venv` has been created. | ||
``` | ||
pyinstaller --onefile --paths=.venv/lib/python3.10/site-packages dbbackupr2.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BACKUP_DIR=/home/my-user/dbbackup | ||
MYSQL_KEEP_DAYS=30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python-dotenv==1.0.1 |