Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to back up the script on time by MySQL in LINUX

Shulou Source: shulou.com Published: 2022-06-03 04:59:41 10月22日 Update

This article is mainly about how MySQL in LINUX back up the script on time. If you are interested, let's take a look at this article. I believe it is of some reference value to everyone after reading how MySQL back up the script on time in LINUX.

(0) backup destination

Backup: tel database

Directory: / mysqlbackup/

Strategy: 3: 00 every day

(1) create a backup user with no backup password backup

Mysql > grant all on tel. To 'backup'@'localhost' identified by "backup"

Provide less permissions:

Mysql > grant select,show view,lock tables,trigger on tel. To 'backup'@'localhost' identified by "backup"

(2) write backup scripts

Shell > vim mysql_backup.sh

#! / bin/sh

# define variable #

Date=date +% Y%m%d

Ago10date=date-d "10 day ago" + "% Y%m%d"

Backuser=backup

Db_host=localhost

Backupdir=/mysqlbackup

# determine whether the storage directory exists #

If [!-d $backupdir]

Then

Mkdir-p $backupdir

Fi

# determine whether the second level storage directory exists #

If [!-d $backupdir/$date]

Then

Mkdir-p $backupdir/$date

Fi

# execute backup command #

/ usr/bin/mysqldump-u$backuser-h $db_host-paired backup`-- single-transaction tel > "$backupdir/$date/tel.sql"

# Delete backups 10 days ago #

If [- d $backupdir/$ago10date]

Then

Rm-rf $backupdir/$ago10date

Fi

(3) add execution permission

Shell > chmod + x mysql_backup.sh

(4) add scheduled tasks

Shell > crontab-l

3 * / usr/bin/sh / mysqlbackup/mysql_backup.sh

Does the above details about how to back up the script in MySQL in LINUX help you? If you want to know more about it, you can continue to follow our industry information section.

Tags: Backups scripts directories content permissions users values tasks interests variables commands passwords data databases articles more sections user names goals policies Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MySQL Linux Shulou Technology MariaDB