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
backup_operator = BackupOperator(hostname='localhost', port=3306, username='root', password='root')
backup_operator.backup()
backup_operator.backup(dbs=['foo_bar_db', 'hello_world_db'])
backup_operator.backup(db_name='foo_bar_db', filename='foo_bar_bak_test.sql')
backup_operator.backup(db_name='foo_bar_db', tables=['foo_user', 'bar_store'], filename='foo_bar_bak_test.sql')
backup_operator.pattern_backup(db_name='foo_bar_db', pattern='%foo%', filename='foo_bar_bak_test.sql')
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')
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
cleanup_operator = CleanupOperator(hostname='localhost', port=3306, username='root', password='root')
cleanup_operator.drop(db_name='foo_bar_db')
cleanup_operator.drop(db_name='hello_world_db', keep_db=False)
cleanup_operator.drop(db_name='foo_bar_db', tables=['foo_user', 'bar_weather'])
cleanup_operator.pattern_drop(db_name='foo_bar_db', pattern='%foo%')
Migrate
from mysql_operator import MigrateOperator
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')
migrate_operator.import_database()
migrate_operator.import_database(db_name='foo_bar_db')
migrate_operator.export_database()
migrate_operator.export_database(db_name='foo_bar_db')
Buy me a coffee, if you like it!