文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>每小时Dump所有mysql数据库到NAS存储设备上

每小时Dump所有mysql数据库到NAS存储设备上

时间:2008-12-08  来源:kevinadmin

一 下载该shell脚本

二 针对你的操作系统环境,修改这个脚本里面的设置

三 把脚本加入crontab里,设定每小时运行shell脚本,例如

# Backup database every 1 hr to /nas
@hourly /root/scripts/db1hr.backup.sh >/dev/null 2>&1

以下是该shell脚本的源代码:

#!/bin/bash # A simple shell script to backup all MySQL Server Database # Dump all MySQL database every hour from raid10 db disk to /nas/mysql # Each dump will be line as follows: # Directory: /nas/mysql/mm-dd-yyyy # File: mysql-DBNAME.04-25-2008-14:23:40.gz # Full path: /nas/mysql/mm-dd-yyyy/mysql-DBNAME.04-25-2008-14:23:40.gz # ------------------------------------------------------------------------- # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- NOW=$(date +"%m-%d-%Y") # mm-dd-yyyy format FILE="fs-full-$NOW.tar.gz" BAK="/nas/mysql/${NOW}"   ### Server Setup ### #* MySQL login user name *# MUSER="root"   #* MySQL login PASSWORD name *# MPASS="YOUR-PASSWORD"   #* MySQL login HOST name *# MHOST="127.0.0.1"   #* MySQL binaries *# MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" GZIP="$(which gzip)"   # assuming that /nas is mounted via /etc/fstab if [ ! -d $BAK ]; then mkdir -p $BAK else : fi # get all database listing DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"   # start to dump database one by one for db in $DBS do FILE=$BAK/mysql-$db.$NOW-$(date +"%T").gz # gzip compression for each backup file $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE done
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载