The dbManager is a CLI tool which can be used to manage remote or local MySQL or MariaDB.
I need a tool to help to manage databases in CI/CD pipelines, so I start dbManager.
- Mariadb or MySQL clients
- dbManager needs 3 environment variables:
DB_HOST
: The address or hostname of database, Example:DB_HOST=db.production
DB_USER
: The user which have access databaseDB_PASSWORD
: The password of user
Syntax:
dbManager create <DatabaseName>
create will be used to create a database
NOTE: If desired database exists, It returns exit code 1
Example:
# Create database druapl if it doesn't exist
dbManager create drupal
Syntax:
dbManager drop <DatabaseName>
drop will drop the database
NOTE: Exit codes: Database exist exit code 0 , Database does not exist exit code 1
Example:
# Create database druapl if it exists
dbManager drop drupal
Syntax:
dbManager exist <DatabaseName>
exist check if the database exists
NOTE: If desired database doesn't exist, It returns exit code 0 and exit code 1
Example:
# check if database drupal exists
dbManager exist drupal
Syntax:
dbManager user create <User> <Password>
user create will be used to create user
NOTE: The user can access database host both remotely and locally
NOTE: The user doesn't permission to access anything in database host
Example:
# Create user armin with password ThisIsASecret
dbManager user create armin ThisIsASecret
Syntax:
dbManager user delete <User>
user create will be used to delete user
NOTE: If desired user doesn't exists, It returns exit code 1
NOTE: The delete user does not revoke user permissions
Example:
# delete user armin
dbManager user delete armin
Syntax:
dbManager access grant <User> <Database>
access grant give user full access to a database
NOTE: If user or database don't exist, It returns exit code 1
Example:
# give user armin full access of database drupal
dbManager access grant armin drupal
Syntax:
dbManager access revoke <User>
access grant revoke all access of user
NOTE: If user doen't exist, It returns exit code 1
Example:
# revoke all accesses of user armin
dbManager access revoke armin
Syntax:
dbManager sync <SourceDB> <DestinationDB>
sync sync destination database with source database
NOTE: If source database doen't exist, It returns exit code 1
NOTE: If ddestination database doen't exist, It will be created
Example:
# sync drupal-test database with drupal database
dbManager sync drupal drupal-test
Syntax:
dbManager restore <Database> <Dumpfile>
restore Restore database from a dumpfile
NOTE: If dumpfile doen't exist, It returns exit code 1
NOTE: If database doen't exist, It will be created
Example:
# restore database drupal from file stage.sql
dbManager restore drupal stage.sql
Syntax:
dbManager view databases
view databases view list of all databases on the database host
Example:
# list all databases
dbManager view databases
Syntax:
dbManager view users
view users view list of all users on the database host
Example:
# list all users
dbManager view users
Syntax:
dbManager view tables <Database>
tables view all tables in a desired database
NOTE: If database doen't exist, It returns exit code 1
Example:
# list all tables in drupal database
dbManager view tables drupal
The image is based on bitnami/minideb
and will be run via dbmanager
user with id 1001
.
To build image we use Earthly
which you can have look Earthfile
for more infromation.
Example:
docker run -it --rm --name dbmanager --env DB_HOST=db.production --env DB_USER=armin --env DB_PASSWORD=ThisIsASecret heiran/dbmanager dbManager create test
# Kubernetes
kubectl run dbmanager -it --rm --image=heiran/dbmanager --env DB_HOST=<DB> --env DB_USER=<USER> --env DB_PASSWORD=<PASSWORD> -- dbManager view databases
- Clone the repository
- Create
dbManager
directory/var/dbManager
- Copy all files in
CLI
directory to/var/dbManager
and make them executable
chmod x -R /var/dbManager
- Move
/var/dbManager/dbManager
file to a folder in your path
install -o root -g root -m 0755 /var/dbManager/dbManager /usr/local/bin/dbManager
- Add K8s Job template
- ...