A tool for backup/cleanup/migrate mysql
Project description
mysql-operator
A package for backup / cleanup / migrate mysql database.
Description:
A tool for backup / cleanup / migrate mysql.
This package can make you backup / cleanup / migrate mysql more earlier with python3.
Initial testing data
- download
https://github.com/chienfeng0719/mysql-operator/blob/develop/init.sql
- run command
mysql-operator -r init.sql
How To Use:
You can use mysql-operator through command line for backup/restore/drop database as the following example:
CLI
mysql-operator -b foo_bar_db -> backup foo_bar_db
mysql-operator -d foo_bar_db -> drop foo_bar_db
mysql-operator -r backup_2020-10-10.sql -> restore data from backup_2020-10-10.sql
You can also do some advanced operate with python:
Backup
from mysql_operator import BackupOperator
# init object
backup_operator = BackupOperator(hostname='localhost', port=3306, username='root', password='root')
# backup all database
backup_operator.backup()
# backup multiple databases
backup_operator.backup(dbs=['foo_bar_db', 'hello_world_db'])
# backup database『foo_bar_db』
backup_operator.backup(db_name='foo_bar_db', filename='foo_bar_bak_test.sql')
# backup database『foo_bar_db』with tables ['foo_user', 'bar_store']
backup_operator.backup(db_name='foo_bar_db', tables=['foo_user', 'bar_store'], filename='foo_bar_bak_test.sql')
# backup database『foo_bar_db』with table which table name like '%foo%'
backup_operator.pattern_backup(db_name='foo_bar_db', pattern='%foo%', filename='foo_bar_bak_test.sql')
# backup database『foo_bar_db』with table 'bar_store' where id <= 2 AND branch '%Jammu%'
backup_operator.filter_backup(db_name='foo_bar_db',
table_name='bar_store',
filter_="id <= 2 AND branch like '%Jammu%'",
filename='foo_bar_bak_test.sql')
# restore backup
backup_operator.restore(db_name='foo_bar_db', filename='foo_bar_bak_test.sql')
NOTICE: The filter_ argument with filter_backup must use double quotes
Cleanup
from mysql_operator import CleanupOperator
# init object
cleanup_operator = CleanupOperator(hostname='localhost', port=3306, username='root', password='root')
# drop all tables in『foo_bar_db』
cleanup_operator.drop(db_name='foo_bar_db')
# drop database『hello_world_db』
cleanup_operator.drop(db_name='hello_world_db', keep_db=False)
# drop tables ['foo_user', 'bar_weather'] in『foo_bar_db』
cleanup_operator.drop(db_name='foo_bar_db', tables=['foo_user', 'bar_weather'])
# drop tables in『foo_bar_db』 which table name like '%foo%'
cleanup_operator.pattern_drop(db_name='foo_bar_db', pattern='%foo%')
Migrate
from mysql_operator import MigrateOperator
# init object
migrate_operator = MigrateOperator(hostname='localhost',
port=3306,
username='root',
password='root',
target_hostname='192.168.1.1',
target_port=3306,
target_username='root',
target_password='root')
# import all database from target host
migrate_operator.import_database()
# import database『foo_bar_db』from target host
migrate_operator.import_database(db_name='foo_bar_db')
# export all database from to host
migrate_operator.export_database()
# export database『foo_bar_db』to target host
migrate_operator.export_database(db_name='foo_bar_db')
Buy me a coffee, if you like it!
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
mysql-operator-1.0.0.tar.gz
(6.0 kB
view details)
Built Distribution
File details
Details for the file mysql-operator-1.0.0.tar.gz
.
File metadata
- Download URL: mysql-operator-1.0.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96ee346329a5b0967a2eecc5bea14bc3358be14b20d698a3149c858c97165825 |
|
MD5 | 9c770fa6bc14aa7b56df4b887bc97517 |
|
BLAKE2b-256 | e2a279484201560d5a76ade1fa4f8047641b49a92ae18fb826dd38dc54bacdf2 |
File details
Details for the file mysql_operator-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: mysql_operator-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6ce1a32bd74df40bca19e412281c483d30a8d57fff529c5a51a4deb08ead667 |
|
MD5 | 8cab36a360861d017a410ff8a6b18ba0 |
|
BLAKE2b-256 | ca99ec7e5212940ff67205959c6e857bb3b2584eec303517961dbdadbbc88ff0 |