mysql regular backup script newbie tutorial

 

Sh script writing

#!/bin/bash
# 数据库认证
 user="root"
 password="root"
 host="127.0.0.1"
 db_name="fmc"
# 其它
 backup_path="/home/mysqlbackup"
 date=$(date +"%d-%b-%Y")
# 设置导出文件的缺省权限
 umask 177
# Dump数据库到SQL文件
 mysqldump --user=$user --password=$password --host=$host $db_name > $backup_path/$db_name-$date.sql

New Location good backup file mysql

The current script storage location /home/script/mysql_backup.sh
first test under

sh /home/script/mysql_backup.sh

Discovery has generated a success

The next step

Open regular tasks

crontab -e

#mysql_backup
21 14 * * * sh /home/script/mysql_backup.sh

Published 263 original articles · won praise 46 · views 370 000 +

Guess you like

Origin blog.csdn.net/qq_27229113/article/details/103957315