If you are a beginner in the practical application of MySQL scheduled data backup and you are not familiar with the practical application of MySQL scheduled data backup, the following articles will provide you with more comprehensive knowledge. I hope it will help you in this regard.
You can rewrite it as needed :)
Run Java code
- bash MySQL_backup.sh
- bash MySQL_backup.sh
Java code
- #!/bin/bash
- #This is a ShellScript For Auto DB Backup
- #Powered by liuzheng
System variable definition
- 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
Create backup file
- if [ ! -d $BackupPath ]; then
- mkdir $BackupPath
- fi
- echo "---------------------------"
- echo $(date +"%y-%m-%d %H:%M:%S")
- echo "---------------------------"
Delete historical files from MySQL scheduled data backup
- if [ -f $OldFile ]; then
- rm -f $OldFile >> $LogFile
- echo "[$OldFile]Delete Old File Success!"
- else
- echo "not exist old file!"
- fi
New File
- 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
The above content is an introduction to MySQL regular data backup. I hope you will get some benefits.