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 閱讀(273) 評論(0)  編輯  收藏 所屬分類: LinuxMysql

          導航

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

          統(tǒng)計

          常用鏈接

          留言簿(7)

          隨筆分類

          隨筆檔案

          相冊

          Photo

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 邹城市| 舒兰市| 九江市| 合作市| 胶州市| 汾阳市| 天峻县| 天气| 广丰县| 建湖县| 塔城市| 武宁县| 伽师县| 分宜县| 濮阳县| 柯坪县| 乳源| 安图县| 南京市| 德州市| 南涧| 开鲁县| 玛多县| 紫阳县| 乐清市| 乌审旗| 凌云县| 民县| 桃江县| 平顶山市| 新晃| 眉山市| 东乌珠穆沁旗| 得荣县| 遂昌县| 徐闻县| 西丰县| 永寿县| 高雄市| 平潭县| 平乐县|