实现MySQL定时数据备份的操作步骤
程序员文章站
2024-02-10 21:49:40
...
以下的文章主要介绍的是MySQL定时数据备份的具体操作,如果你对MySQL定时数据备份相关的实际操作有兴趣的话,你就可以对以下的文章点击观看了。同时文章也有更多相关推荐 可以根据自己的需求自己改写: MySQL定时数据备份;运行Java代码 bashmysql_backup.sh
以下的文章主要介绍的是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文章版
推荐阅读