Tao

          Tao obeys its own inherent Nature

          How To: using bash script to backup MySql

          Create a file backup_db.sh, and paste the following contents:
          #get the first parameter as the database name
          DATABASE=$1
          #if no database specified, then you can set the default one
          if [ -z $DATABASE ]; then
          DATABASE=default_database_name_here
          fi

          #mysql user and password to backup the database. MYSQLUSER=mysql_user MYSQLPWD=mysql_password #path to backup ARCHIVEPATH=~/backup/db_backup DATE=`date +%Y%m%d` YEAR=`date +%Y` MONTH=`date +%m` FOLDER_MONTH=$ARCHIVEPATH/$YEAR$MONTH if [ ! -d $FOLDER_MONTH ]; then
          echo "mkdir $FOLDER_MONTH" mkdir $FOLDER_MONTH fi # Backup echo "mysqldump -u$MYSQLUSER -p$MYSQLPWD $DATABASE | gzip > $FOLDER_MONTH/$DATABASE-$DATE.sql.gz" mysqldump -u$MYSQLUSER -p$MYSQLPWD $DATABASE | gzip > $FOLDER_MONTH/$DATABASE-$DATE.sql.gz

           

          and you can add the script to cron job under *nix and schedule under windows:

          *nix:

          Save the following text in file: db_backup.at

          10 * * * * ~/backup/backup_db.sh databasename

          and call

          crontab db_backup.at

          You need to change the period to run the script for your business, e.g. each day, each week etc.


           

          posted on 2007-11-13 15:49 wade 閱讀(270) 評論(0)  編輯  收藏 所屬分類: LinuxMysql

          導航

          <2007年11月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          統計

          常用鏈接

          留言簿(7)

          隨筆分類

          隨筆檔案

          相冊

          Photo

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 新晃| 清流县| 万盛区| 南陵县| 青铜峡市| 大埔区| 抚远县| 海南省| 阳西县| 丰台区| 城市| 德昌县| 隆昌县| 惠东县| 华容县| 濉溪县| 冕宁县| 淮南市| 洛浦县| 云霄县| 文水县| 镇安县| 如皋市| 麻栗坡县| 平泉县| 城口县| 大荔县| 虎林市| 秦安县| 新郑市| 中方县| 旬阳县| 吴旗县| 九寨沟县| 安龙县| 孟津县| 莒南县| 上高县| 永顺县| 开化县| 福州市|