以下的文章主要介紹的是MySQL定時數據備份的具體操作,如果你對MySQL定時數據備份相關的實際操作有興趣的話,你就可以對以下的文章點擊觀看了。同時文章也有更多相關推薦 可以根據自己的需求自己改寫:
MySQL定時數據備份;運行Java代碼
- bash mysql_backup.sh
- bash mysql_backup.sh
- Java代碼
- !/bin/bash
- This is a ShellScript For Auto DB Backup
- Powered by liuzheng
系統變量定義
- DBName=Bulletin_production
- DBUser=root
- DBPasswd=
- BackupPath=/home/worker/mysql_backup/
- NewFile="$BackupPath"db$(date +%y%m%d).tar.gz
- DumpFile="$BackupPath"db$(date +%y%m%d).sql
- OldFile="$BackupPath"db$(date +%y%m%d --date='1 days ago').tar.gz
MySQL定時數據備份:創建備份文件
- if [ ! -d $BackupPath ]; then
- mkdir $BackupPath
- fi
- echo "---------------------------"
- echo $(date +"%y-%m-%d %H:%M:%S")
- echo "---------------------------"
刪除歷史文件
- if [ -f $OldFile ]; then
- rm -f $OldFile >> $LogFile
- echo "[$OldFile]Delete Old File Success!"
- else
- echo "not exist old file!"
- fi
新文件
- if [ -f $NewFile ]; then
- echo "[$NewFile] The Backup File is exists,Can't Backup! "
- else
- mysqldump -u $DBUser $DBName > $DumpFile
- tar czvf $NewFile $DumpFile
- rm -rf $DumpFile
- echo "[$NewFile]Backup Success!"
- fi
- !/bin/bash
- This is a ShellScript For Auto DB Backup
- Powered by liuzheng
系統變量定義
- DBName=Bulletin_production
- DBUser=root
- DBPasswd=
- BackupPath=/home/worker/mysql_backup/
- NewFile="$BackupPath"db$(date +%y%m%d).tar.gz
- DumpFile="$BackupPath"db$(date +%y%m%d).sql
- OldFile="$BackupPath"db$(date +%y%m%d --date='1 days ago').tar.gz
MySQL定時數據備份創建備份文件
- if [ ! -d $BackupPath ]; then
- mkdir $BackupPath
- fi
- echo "---------------------------"
- echo $(date +"%y-%m-%d %H:%M:%S")
- echo "---------------------------"
刪除歷史文件
- if [ -f $OldFile ]; then
- rm -f $OldFile >> $LogFile
- echo "[$OldFile]Delete Old File Success!"
- else
- echo "not exist old file!"
- fi
新文件
- if [ -f $NewFile ]; then
- echo "[$NewFile] The Backup File is exists,Can't Backup! "
- else
- mysqldump -u $DBUser $DBName > $DumpFile
- tar czvf $NewFile $DumpFile
- rm -rf $DumpFile
- echo "[$NewFile]Backup Success!"
- fi
聲明:JavaEye文章版