首页
登入
标签
留言
centos 自动备份mysql数据库 - 搜集资料
大
|
中
|
小
2012/04/01 22:06 ,
mdy
Linux 服务器
,
评论(0)
,
阅读(2530)
, Via 本站原创
Tags:
crontab
还是crontab 把它放入任务列表/usr/tmp/task : 51 14 * * * /usr/tmp/mysql_media_bak.sh mysql_media_bak.sh shell代码如下: --------------代码开始---------------烦躁的分割线-------------------------------------------- #!/bin/sh # mysql_media_bak.sh db_user="webroot" db_passwd="123123" db_host="localhost" db_name="media" # the directory for story your backup file. backup_dir="/var/www/html/media/mysql_bak" # date format for backup file (dd-mm-yyyy) time="$(date +"%Y-%m-%d-%H-%M-%S")" # mysql, mysqldump and some other bin's path MYSQL="/usr/bin/mysql" MYSQLDUMP="/usr/bin/mysqldump" GZIP="/bin/gzip" $MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db_name | $GZIP -9 > "$backup_dir/$db_name"_"$time.gz" ---------------------代码结束---------------烦躁的分割线------------------------------------------------------------- 这个代码是备份整个数据库的所有数据库 #!/bin/sh # mysql_backup.sh: backup mysql databases and keep newest 5 days backup. # # Last updated: 20 March 2006 # ---------------------------------------------------------------------- # This is a free shell script under GNU GPL version 2.0 or above # Copyright (C) 2006 Sam Tang # Feedback/comment/suggestions : http://www.real-blog.com/ # ---------------------------------------------------------------------- # your mysql login information # db_user is mysql username # db_passwd is mysql password # db_host is mysql host # ----------------------------- db_user="webroot" db_passwd="123123" db_host="localhost" # the directory for story your backup file. backup_dir="/var/www/html/media/mysql_bak" # date format for backup file (dd-mm-yyyy) time="$(date +"%d-%m-%Y")" # mysql, mysqldump and some other bin's path MYSQL="/usr/bin/mysql" MYSQLDUMP="/usr/bin/mysqldump" MKDIR="/bin/mkdir" RM="/bin/rm" MV="/bin/mv" GZIP="/bin/gzip" # check the directory for store backup is writeable test ! -w $backup_dir && echo "Error: $backup_dir is un-writeable." && exit 0 # the directory for story the newest backup test ! -d "$backup_dir/backup.0/" && $MKDIR "$backup_dir/backup.0/" # get all databases all_db="$($MYSQL -u $db_user -h $db_host -p$db_passwd -Bse 'show databases')" for db in $all_db do $MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db | $GZIP -9 > "$backup_dir/backup.0/$time.$db.gz" done # delete the oldest backup test -d "$backup_dir/backup.5/" && $RM -rf "$backup_dir/backup.5" # rotate backup directory for int in 4 3 2 1 0 do if(test -d "$backup_dir"/backup."$int") then next_int=`expr $int + 1` $MV "$backup_dir"/backup."$int" "$backup_dir"/backup."$next_int" fi done exit 0; ---------------------所有数据库备份代码结束-------------------------------------------------------------------
centos 自动备份增
centos Apach
分类
Linux 服务器
[174]
Mysql
[18]
PHP
[139]
python
[1]
Dedecms
[34]
Discuz
[6]
Jquery代码
[56]
Css 重构
[11]
源码收藏
[12]
Excel函数学习
[29]
网络拾贝
[21]
心情日记
[12]
社会
[3]
统计
访问次数 1376776
今日访问 307
日志数量 516
评论数量 0
引用数量 0
留言数量 0
注册用户 1
在线人数 15
链接
PHP
清风的网络空间
扶凯的博客
张宴的博客
风雪之隅博客
WEB开发笔记
phpwinne
拿福能中国
平凡的世界
三水清
钱运来
开发手册
LINUX
python
开源中国
河北Linux用户组
WEB前端设计
dansion的日志
CSSBOX.net
Gracecode.com
19楼
网易的UED
笨笨剥壳
网络文摘
coury博客