Bash script to easily
- get DB credentials from your CMS/framework config file
- export DB,
- import DB,
- search in DB,
- search/replace in DB,
- pull database from remote server,
- and lot more. Look at the screenshot above!
- WordPress
- Laravel
- Prestashop 1.6
- Prestashop 1.7
- ...
- MySQL
- PostgreSQL
Please request your engine by creating new issue on Github! Give me your engine's config file example and I'll add it to the script. π
Fast way (in one step). Worked on Mac, Linux and Windows (terminals with bash support)
Stable version π
eval "$(curl "https://raw.githubusercontent.com/michaelradionov/gg_installer/master/gg_installer.sh")" && gg_installer bdsm
Since BDSM can install other usefull scripts, you can install them simply running
bdsm --install-all
This command will install:
- Git aliases
- HelloBash script
- My favorite Micro Editor
- Laravel aliases
- Docker aliases
- Jira aliases
- Random aliases
cd
in website root directory- Execute
bdsm
- Follow instructions. Enjoy! See features description below.
π° Donate. Nah! Just give this repo a star and I will appreciate it! βοΈ
--backup
option is made to simply create DB backup file with name like my_database_mysql_2019-10-25.sql
and quit. --backup
option will not open interactive mode.
bdsm --backup [-d <backups folder>] [-n <backups max count>] [--zip]
Example:
bdsm --backup -d /backups/ -n 14 --zip
-d
is optional parameter. Use it to specify backups directory. By default, script will usebd_backups
folder in root of your project (website)-n
is optional parameter. Use it to limit total number of backups. By default, there is no limit.--zip
is optional parameter. Use it to automatically compress database backups with tar (tar.gz)
You can use BDSM as a simple DB backuping tool by putting this to your cron job! I suggest you to use it like this
Daily Cron job example:
0 0 * * * /bin/bash -c "source ~/.gg_tools/bdsm.sh && cd <website path> && bdsm --backup -d <backups folder> --zip "
For example, you can keep 7 daily backups, 4 weekly and 6 monthly backups in different folders like this
WEBSITE_PATH=<website path>
BACKUPS_PATH=/db_backups
# 7 daily backups
0 0 * * * /bin/bash -c "source ~/.gg_tools/bdsm.sh && cd "$WEBSITE_PATH" && bdsm --backup -d "$BACKUPS_PATH"/daily -n 7 --zip"
# 4 weekly backups
0 0 * * 0 /bin/bash -c "source ~/.gg_tools/bdsm.sh && cd "$WEBSITE_PATH" && bdsm --backup -d "$BACKUPS_PATH"/weekly -n 4 --zip"
# 6 monthly backups
0 0 1 * * /bin/bash -c "source ~/.gg_tools/bdsm.sh && cd "$WEBSITE_PATH" && bdsm --backup -d "$BACKUPS_PATH"/monthly -n 6 --zip"
where path/to/your/website
is obviously a path to your website!
- When you execute BDSM it will automatically detect you engine, check for config file and parses it to get DB credentials. Then all of that data will be stored in your current Bash session.
- Show credentials. Pretty obvious, isn't it?
- Export DB locally. This option will dump your database into file. If you are using Docker, then you should use option 12 before. See description below.
- Search in dump. This option is responsible for searching in exported DB dump file.
- Search/Replace in dump. Obviously, this option will search/replace any given data. First step will be search, then (optionally) replacement. Please keep in your mind that BDSM doesn't support RegExp for now, only simple string values.
- Import dump. If BDSM successfully determined your DB credentials OR if your entered them manually (option 11), then "Import dump" option will... Guess what? It will import you dump file to database. What a surprise!
- Pull DB from remote server. This is very cool feature that allows you do a bunch of stuff IN ONE RUN! What it will do is:
- SSH to a given remote server
- Check if there is a Docker container with "mysql" in its name
- Depending on previous step it will export DB to dump file from localhost or from Docker container
- SCP exported dump to you on youΠΊ local machine (depending where you launched BDSM)
- Delete exported dump from the remote server
- Delete dump. Deletes local dump.
- Self-update. You can update BDSM to the last version by this option.
- Install other scripts. Convinious way to install or update:
- Micro Editor. GUI like editro in your terminal and alias it to "m" command. See more https://micro-editor.github.io/
- Hello Bash. My handy Bash prompt configurator. I use it everywhere. See more https://github.com/michaelradionov/helloBash
- My awesome Git aliases. See more here https://github.com/michaelradionov/aliases
- Other aliases for Jira, Laravel, Docker and other.
- Look for dump elsewhere locally. This option will help you to point BDSM to already existing dump file.
- Enter credentials manually. Manually input DB name, user and password.
- Choose/forget local Docker container. In fact it means "enter Docker mode". Here you can:
- Let BDSM to find container with "mysql" in its name
- Explicitly input Docker container's name
- Quit Docker mode
- Bash support. Check by executing
bash --version
- Mysql CLI support. Check by executing
mysql --version
andmysqldump --version
- cURL CLI support. Check by executing
curl --version
- Sourcing ~/.bashrc file on session start. Check by:
- executing
echo 'echo "It works"' >> ~/.bashrc
- then start new terminal session. If you see "It works!" then you good.
- Then delete this line from your ~/.bashrc.
- executing
- For the previous item. If you don't know where is ~/.bashrc, you should execute
cd
(without parameters), thenpwd
. Output will be your home path, it equals~
.
If you have literally ANY trouble with installing and using script, please, create an issue in Github repo https://github.com/michaelradionov/bdsm.
- Edit the variable
BDSM_VERSION
in bdsm.sh - Update CHANGELOG.md