A script for backup mysql

A script for backup mysql


Hi all,

Here is a nice script for backup your mysql-database.

With this simple linux mysql backup script you can do your easy mysql backup by menu-driven user inputs.

conditions

linux, bash, mysql (http://dev.mysql.com/downloads/).

a backup user with backup-privileges.

Use the following command for creating this one:

GRANT PROCESS,SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER
ON *.*
TO ‚BackupUser’@’localhost‘
IDENTIFIED BY ‚BackupPassword‘;
FLUSH PRIVILEGES;

how to call the script for backup for mysql database:

bash easymysqlbackup or ./easymysqlbackup

how to use script for backup mysql:

with this simpl script you have 2 options.
1.) You can only show your available databases

2.) You can choose one or more databases to backup.

mysqlbackup_choice

click to enlarge

before the backup mysql will start, the script show you the command that will be execute (see next screenshot).
You can use this as a template for sheduling a automatic backup in the crontab.

mysqlbackup_command

 

For advanced users:

In the mysqldump backup script you can change following default settings:

MYSQLUSER=BackupUser
MYSQLPW=BackupPassword
DATABASE_BACKUP_DIR=/tmp
DATABASE_BACKUP_FILE=“mysql_backup_`date +%d%m%y_%H%M`“

The MYSQLUSER and the MYSQLPW Parameter are equal to the user / password we created at the beginning.
If you already have an user in your database or you want to use the root user (not recommended) you can set the data here.
The DATABASE_BACKUP_DIR is the default backup directory for the database. You can change the path in the script but you also can change it during the backup-process. DATABASE_BACKUP_FILE is the filename for the backupfile which contains the current date and time. Feel free to change it, if you want ;).

Download shell script to backup mysql database

Attention: The author does not assume liability for errors or data loss! 

Kommentare sind abgeschaltet.