Home >Database >Mysql Tutorial >ubuntu下设置mysql自动备份的例子_MySQL

ubuntu下设置mysql自动备份的例子_MySQL

WBOY
WBOYOriginal
2016-06-01 13:23:421057browse

Ubuntu

bitsCN.com 1、创建保存mysql备份文件的路径 /mysqldata
#mkdir /mysqldata

2、创建/usr/sbin/bakmysql 文件
#nano /usr/sbin/bakmysql

输入:

#!/bin/sh
name='date+%Y%m%d'
mysqldump --all-databases -uroot -p密码 > /var/mysqlbak/mysql.sql


注:--all-databases 为备份全部数据库到mysqlbak下的mysql.sql文件中,如果把--all-databases替换为test,则只备份test数据库。

3、修改文件属性,使其可执行
# chmod +x /usr/sbin/bakmysql

4、修改/etc/crontab
#nano /etc/crontab

在下面添加:
01 3 * * * root /usr/sbin/bakmysql
表示每天3点钟定时执行备份。

5、重启 crond
# /etc/init.d/cron restar

完成。bitsCN.com
Statement:
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