Home > Database > Mysql Tutorial > Linux自动备份MySQL数据库脚本代码_MySQL

Linux自动备份MySQL数据库脚本代码_MySQL

WBOY
Release: 2016-06-01 13:25:52
Original
1120 people have browsed it

bitsCN.com 在脚本中可设置需要备份的数据库表清单,并且会将备份文件通过gzip压缩。需要注意的是,这段脚本仅适用数据一致性要求不高的环境。

#!/bin/bash
mysql_pwd="password"
mysql_dump="/usr/local/mysql/bin/mysqldump"
cur_year=$(date +"%Y")
cur_month=$(date +"%m")
cur_day=$(date +"%d")
dump_path="/usr/backup/mysql/$cur_year-$cur_month/$cur_day"
arr_tables=(
"table_1"
"table_2"
"table_3"
)
if [ ! -d "$dump_path" ]; then
mkdir -p "$dump_path"
fi
for cur_table in ${arr_tables[*]}; do
$mysql_dump -uroot -p$mysql_pwd --opt mydb $cur_table | gzip > $dump_path/$cur_table.sql.gz
done
bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template