The project needs to be backed up regularly, and the following are its own operating notes
1. Check disk space
# Df-hfilesystem Size used Avail use% mounted on/dev/vda1 40G 3.6G 34G 10%/tmpfs 16G 0 16G 0%/DEV/SHM
This is my current Linux server situation, as to why this is the case, I do not know (I was halfway over, helpless)
Based on the information above, I'll put the backup file under the/dev directory
2. Create a backup directory
Cd/devmkdir BACKUPCD Backup
3. Create a backup shell command
VI bkdatabasename.sh
Enter the following:
1 #!/bin/bash2 mysqldump-uusername-ppassword-hmysqlip DatabaseName >/dev/backup/ databasename_$ (date +%y%m%d_%h%m%s). sql
Compressing a backup
Mysqldump-uusername-ppassword-hmysqlip DatabaseName | gzip >/dev/backup/databasename_$ (Date +%y%m%d_%h%m%s). sql.gz
Note:
Replace the username with the actual user name;
Replace the password with the actual password;
Replace the mysqlip with the MySQL IP;
Replace the DatabaseName with the actual database name;
4. Add executable permissions
chmod u+x bkdatabasename.sh
Add executable permissions to execute first, see if the script is wrong, can not be used properly;
./bkdatabasename.sh
5. Add timed execution tasks
1 # crontab2 -bash:crontab:command not found
Execute crontab command If not found, indicates that no installation is performed;
To install crontab please refer to:http://www.cnblogs.com/dxy1451713982/p/8081569.html
Add a Scheduled task
Crontab-e
*/1 * * * */home/backup/bkdatabasename.sh
Means to execute once per minute, note: For cron expressions, suggest yourself Baidu
6. Test whether the task is performed
1#tail-f/var/log/cron2Dec + -: -:Teniz2318jid47z run-parts (/etc/cron.daily) [22449]: finished Makewhatis.cron3Dec + -: -:Teniz2318jid47z run-parts (/etc/cron.daily) [15753]: Starting Mlocate.cron4Dec + -: -:Teniz2318jid47z run-parts (/etc/cron.daily) [22460]: finished Mlocate.cron5Dec + -: -:Teniz2318jid47z run-parts (/etc/cron.daily) [15753]: Starting PreLink6Dec + -: -: -iz2318jid47z run-parts (/etc/cron.daily) [23799]: finished PreLink7Dec + -: -: -iz2318jid47z run-parts (/etc/cron.daily) [15753]: Starting Readahead.cron8Dec + -: -: -iz2318jid47z run-parts (/etc/cron.daily) [23811]: finished Readahead.cron9Dec + -: -: -iz2318jid47z run-parts (/etc/cron.daily) [15753]: Starting TmpwatchTenDec + -: -: -iz2318jid47z run-parts (/etc/cron.daily) [23849]: finished Tmpwatch OneDec + -: -: -iz2318jid47z anacron[15719]: Job ' cron.daily'terminated
Or go to the directory where you stored the backup files to view, whether there are backup files generated;
Linux MySQL scheduled backup