Skip to content

araminian/dbManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Documentation

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.

How to use

Requirements

  1. Mariadb or MySQL clients
  2. 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 database
    • DB_PASSWORD: The password of user

Commands

create

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

drop

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

exist

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

user

create

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

delete

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

access

grant

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

revoke

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

sync

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

restore

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

view

databases

Syntax:

dbManager view databases

view databases view list of all databases on the database host

Example:

# list all databases
dbManager view databases

users

Syntax:

dbManager view users

view users view list of all users on the database host

Example:

# list all users
dbManager view users

tables

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

How to use dbManager

Use docker image heiran/dbmanager

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

Non-container

  1. Clone the repository
  2. Create dbManager directory /var/dbManager
  3. Copy all files in CLI directory to /var/dbManager and make them executable
chmod +x -R /var/dbManager
  1. 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

TODO

  • Add K8s Job template
  • ...

About

a CLI for managing database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published