The following articles mainly introduce the practical application of MySQL regular data backup. First, we will look at the actual drills of Bash Shell syntax from a related log script and Convert PDF files into jpg files in batches, the following describes the specific content of the article.
For more related recommendations, you can rewrite them 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
To implement MySQL scheduled data backup, you must create a backup file.
- if [ ! -d $BackupPath ]; then
- mkdir $BackupPath
- fi
- echo "---------------------------"
- echo $(date +"%y-%m-%d %H:%M:%S")
- echo "---------------------------"
Delete historical files
- 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.