Home > Database > Mysql Tutorial > body text

mysql实现自动远程备份一办法_MySQL

WBOY
Release: 2016-06-01 13:55:28
Original
969 people have browsed it

一、实现本地自动备份数据库很简单:

1.以root身份登陆

2.计划任务(每天的3:30自动执行 /usr/bin/mysqlbackup)

crontab
0 3:30 * * * /usr/bin/mysqlbackup

3.写一个自动备份数据库脚本

vi /usr/bin/mysqlbackup
#!/bin/bash
mv /home/.../db_bak5.tgz /home/.../db_bak6.tgz
mv /home/.../db_bak4.tgz /home/.../db_bak5.tgz
mv /home/.../db_bak3.tgz /home/.../db_bak4.tgz
mv /home/.../db_bak2.tgz /home/.../db_bak3.tgz
mv /home/.../db_bak1.tgz /home/.../db_bak2.tgz
rm -rf /home/.../db_bak.txt
/usr/bin/mysqldump -uroot -ppassword dbname
> /home/.../db_bak.txt
cd /home/.../
tar czvf db_bak1.tgz db_bak.txt

二、这样每天的3:30就会在本地目录/home/.../下生成相应的数据库备份,开始由于/home/.../目录下缺少数据系统会提示错误,这是正常的

三、至于远程备份可以配合使用ftp或scp命令实现,方法很简单,查一下相关命令的使用,然后再改动一下mysqlbackup脚本就可以了

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