11# sql-backup - Backup your MySQL / MariaDB server !
2+
23[ ![ Codacy Badge] ( https://app.codacy.com/project/badge/Grade/1d6a522144ca4169a0c679bd9d299341 )] ( https://www.codacy.com/gh/williamdes/sql-backup/dashboard?utm_source=github.com& ; utm_medium=referral& ; utm_content=williamdes/sql-backup& ; utm_campaign=Badge_Grade )
34[ ![ Actions Status] ( https://github.com/williamdes/sql-backup/workflows/Run%20tests/badge.svg )] ( https://github.com/williamdes/sql-backup/actions )
45[ ![ codecov] ( https://codecov.io/gh/williamdes/sql-backup/branch/master/graph/badge.svg )] ( https://codecov.io/gh/williamdes/sql-backup )
56[ ![ License: Unlicense] ( https://img.shields.io/badge/license-Unlicense-blue.svg )] ( http://unlicense.org/ )
67[ ![ FOSSA Status] ( https://app.fossa.io/api/projects/git%2Bgithub.com%2Fwilliamdes%2Fsql-backup.svg?type=shield )] ( https://app.fossa.io/projects/git%2Bgithub.com%2Fwilliamdes%2Fsql-backup?ref=badge_shield )
78[ ![ CII Best Practices] ( https://bestpractices.coreinfrastructure.org/projects/1827/badge )] ( https://bestpractices.coreinfrastructure.org/projects/1827 )
9+
810Backup your MySQL / MariaDB server ( structure, data, users, grants, views, triggers, routines, events )
911
1012## Install
1113
1214### Clone the repository
13- ``` bash
15+
16+ ``` sh
1417git clone https://github.com/williamdes/sql-backup.git --depth 1
1518```
19+
1620### Move into the directory
17- ``` bash
21+
22+ ``` sh
1823cd sql-backup
1924```
25+
2026### Copy the configuration example
21- ``` bash
27+
28+ ``` sh
2229cp .env-example .env
2330```
31+
2432### Edit your configuration file
33+
2534#### Nano
26- ``` bash
35+
36+ ``` sh
2737nano .env
2838```
39+
2940#### Vi
3041
31- ``` bash
42+ ``` sh
3243vi .env
33-
3444```
45+
3546### Start backup
47+
3648Execute this command to start the backup !
37- ```
49+
50+ ``` sh
3851./backup.sh
3952```
53+
4054## Extras
4155
4256To use an external env file in a custom location, example :
43- ``` bash
57+
58+ ``` sh
4459
4560export BACKUP_CONFIG_ENVFILE=" /home/myuser/secretbackupconfig.env.txt"
4661
4762./backup.sh
4863
4964unset BACKUP_CONFIG_ENVFILE
5065```
66+
5167You can use the variables of the env file in the ` ON_SUCCESS ` variable, example :
5268
53- ``` bash
69+ ``` sh
5470ON_SUCCESS=" ${BACKUP_DIR} /onsuccessscript.sh"
5571```
5672
57-
5873## Options
5974
60- | NAME | DEFAULT VALUE | OPTIONAL |
61- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------- |
62- | BACKUP_DIR | | NO |
63- | MYSQL_HOST | | NO |
64- | MYSQL_USER | | NO |
65- | MYSQL_PASS | | YES |
66- | MYSQL_PORT | 3306 | YES |
67- | SKIP_DATABASES | | YES |
68- | EXPERT_ARGS | --default-character-set=utf8 --extended-insert=FALSE --single-transaction --skip-comments --skip-dump-date --hex-blob --tz-utc | YES |
69- | ON_SUCCESS | | YES |
70- | SKIP_OP | | YES |
75+ | NAME | DEFAULT VALUE | OPTIONAL |
76+ | ----------------| --------------------------------------------------------------------------------------------------------------------------------| ----------|
77+ | BACKUP_DIR | | NO |
78+ | MYSQL_HOST | | NO |
79+ | MYSQL_USER | | NO |
80+ | MYSQL_PASS | | YES |
81+ | MYSQL_PORT | 3306 | YES |
82+ | SKIP_DATABASES | | YES |
83+ | EXPERT_ARGS | --default-character-set=utf8 --extended-insert=FALSE --single-transaction --skip-comments --skip-dump-date --hex-blob --tz-utc | YES |
84+ | ON_SUCCESS | | YES |
85+ | SKIP_OP | | YES |
7186
7287> ON_SUCCESS is called on script success
7388
7489## Example .env
7590
76- ``` bash
91+ ``` sh
7792BACKUP_DIR=/sql_backup
7893MYSQL_HOST=localhost
7994MYSQL_USER=root
@@ -85,17 +100,17 @@ SKIP_OP=users,grants
85100
86101## Files
87102
88- | NAME | DESCRIPTION |
89- | --------------- | ------------------------------------------- |
90- | database.sql | All the data |
91- | structure.sql | The structure of the databases and tables |
92- | grants.sql | The grants for all users except root |
93- | events.sql | The scheduled events |
94- | views.sql | The views |
95- | triggers.sql | The triggers |
96- | routines.sql | All the procedures & functions |
97- | users.sql | All MySQL users |
98-
103+ | NAME | DESCRIPTION |
104+ | ---------------| -------------------------------------------|
105+ | database.sql | All the data |
106+ | structure.sql | The structure of the databases and tables |
107+ | grants.sql | The grants for all users except root |
108+ | events.sql | The scheduled events |
109+ | views.sql | The views |
110+ | triggers.sql | The triggers |
111+ | routines.sql | All the procedures & functions |
112+ | users.sql | All MySQL users |
99113
100114## License
115+
101116[ ![ FOSSA Status] ( https://app.fossa.io/api/projects/git%2Bgithub.com%2Fwilliamdes%2Fsql-backup.svg?type=large )] ( https://app.fossa.io/projects/git%2Bgithub.com%2Fwilliamdes%2Fsql-backup?ref=badge_large )
0 commit comments