Backup your MySQL / MariaDB server ( structure, data, users, grants, views, triggers, routines, events )
git clone https://github.com/williamdes/sql-backup.git --depth 1
cd sql-backup
cp .env-example .env
nano .env
vi .env
Execute this command to start the backup !
./backup.sh
To use an external env file in a custom location, example :
export BACKUP_CONFIG_ENVFILE="/home/myuser/secretbackupconfig.env.txt"
./backup.sh
unset BACKUP_CONFIG_ENVFILE
You can use the variables of the env file in the ON_SUCCESS
variable, example :
ON_SUCCESS="${BACKUP_DIR}/onsuccessscript.sh"
NAME | DEFAULT VALUE | OPTIONAL |
---|---|---|
BACKUP_DIR | NO | |
MYSQL_HOST | NO | |
MYSQL_USER | NO | |
MYSQL_PASS | YES | |
MYSQL_PORT | 3306 | YES |
SKIP_DATABASES | YES | |
EXPERT_ARGS | --default-character-set=utf8 --extended-insert=FALSE --single-transaction --skip-comments --skip-dump-date --hex-blob --tz-utc | YES |
ON_SUCCESS | YES | |
SKIP_OP | YES |
ON_SUCCESS is called on script success
BACKUP_DIR=/sql_backup
MYSQL_HOST=localhost
MYSQL_USER=root
MYSQL_PASS=root
MYSQL_PORT=3306
SKIP_DATABASES=mysql,sys,information_schema,performance_schema,phpmyadmin
SKIP_OP=users,grants
NAME | DESCRIPTION |
---|---|
database.sql | All the data |
structure.sql | The structure of the databases and tables |
grants.sql | The grants for all users except root |
events.sql | The scheduled events |
views.sql | The views |
triggers.sql | The triggers |
routines.sql | All the procedures & functions |
users.sql | All MySQL users |