Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report