Required to back up all the libraries, required to compress the package, the name of the package will take months and days.
source files, or source directories, are required to be deleted after the compressed package has been completed.
Tar with bzip2 compression. The scheduled task is 1:30 execution. After the success of the request to send mail to your QQ mailbox.
The message content. Do you want to include the compressed file name successfully? and size?
#!/bin/bash
#write by Lijun
#Date 2014-08-12
#==================
#备份数据库
Mkdir/backup 2>>/dev/null
Mkdir/mysql-bak 2>>/dev/null
mysqldump-uroot-p123456--all-databases >/backup/all.sql
#==================
#将数据库内容打成tar包, delete source directory and source file, send mail
Name= "MYSQL_BAK.TAR.BZ2"
rm-rf/mysql-bak/*
Tar cjvf/mysql-bak/$name-' date +%f-%t '/backup/* 2>>/dev/null && rm-rf/backup
Size= "' Du-sh/mysql-bak/*|awk ' {print '} '"
If [$?-eq 0]
Then
/ETC/INIT.D/HTTPD Restart 2>>/dev/null
echo "/mysql-bak/$name is OK and the size is $size" |mail-s "MySQL bak" QQ number. com && echo "Send mail OK"
Else
echo "Tar failed ..."
Fi
Crontab-e
* */1 * * * Bash script location