ubantu下MySQL数据库备份方法
2015-09-07 09:58
531 查看
1、编辑/etc/crontab文件设定定时任务,在制定时间执行backup_databases.sh
vi /etc/crontab
2、编写backup_databases.sh,内容如下:
3、手动创建目录/backup
vi /etc/crontab
# /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) 25 9 * * * root sh /home/autotest/backup_databases.sh
2、编写backup_databases.sh,内容如下:
#!/bin/bash # Set the backup filename and directory DATE=`date +%Y%m%d` # e.g 20101025 FILENAME="trunk_development_database_$DATE.sql"; BACKUPDIR="/backup/"; # Database Credentials DBUSER="root"; DBPWD="123qwe^&*"; DBNAME="trunk_development"; # Change to the root directory cd / # Where is our gzip tool for compression? # The -f parameter will make sure that gzip will # overwrite existing files GZIP="/bin/gzip -f"; # Delete old backups older than 3 days find /backup/trunk_development_*gz -mtime +3 -exec rm {} \; # execute the database dump mysqldump --user=$DBUSER --password=$DBPWD --add-drop-table --databases $DBNAME > $BACKUPDIR$FILENAME # compress the database backup$GZIP $BACKUPDIR$FILENAME
3、手动创建目录/backup
相关文章推荐
- mysql安装完成无法修改密码
- MySQL读写分离Atlas
- LNMP中MYSQL数据迁移
- 一千行MySQL学习笔记
- Mysql 删除重复的记录
- MySQL 错误日志 测试
- Mac OS X 10.10 Yosemite下面解决XAMPP无法开启mysql的问题
- 如何在使用MAMP环境下安装MySQLdb
- mysql复合索引与普通索引总结
- mysql 更改默认数据目录
- mysql错误代码1045
- mysql主主同步配置
- 查询mysql日志以及slow sql
- Mysql命令大全
- mysql之explain
- mysql安装
- 命令行连接mysql服务器时 报Can't connect to local MySQL server through socket 'xxx.sock'错误
- MySQL分表与分区
- MySQL(十五)之基于ssl加密搭建含有gtid特性的MySQL主从复制
- MySQL 错误日志 Error log