MySQL automatic backup in linux send mail to specified mailbox code

Source: Internet
Author: User
Tags email account microsoft mail mysql automatic backup server port

First write the exported command

Used a

Mysqladmin Ping

Mysqldump

Then add the attachment to send in the message

Using the corresponding COM

Last pause to see the situation

Reference:

Http://hi.baidu.com/zd8695/blog/item/ae50b21c4b398a8087d6b6ac.html

See Program:

@echo on
:: MySQL directory and the letter and path of the corresponding letter and current BAT file
Set Mysql_home=h:wampbinmysqlmysql5.5.16bin
Set Mysql_dir=h:
Set Execute_dir=c:
Set Execute_home=c:usersfartpigdesktop

:: Email account password
Set email_account=******@126.com
Set email_pass=******

echo Start

echo Save path

Echo%cd%
Set current_dir=%cd%

echo Export SQL
%mysql_dir%
CD%mysql_home%

Echo Try MySQL
Mysqladmin Ping

Mysqldump-u root-proot plane >plane.sql


echo Send mail
%execute_dir%
CD%current_dir%
Start%execute_home%mail.vbs%email_account%%email_pass%%mysql_home%/plane.sql

echo Send success
Pause

corresponding corresponding Mail.vbs

function Send_mail (you_account,you_password,send_email,send_email2,send_topic,send_body,send_attachment)
' Code by Netpatch Changed by ZD8695
' VBS SEND MESSAGE parameter description
' You_account: Your email account
' You_password: Your email password
' Send_email:
' Primary Mailing Address
' Send_email2: Alternate email address
' Send_topic:
' Message subject
' Send_body:
' Message content
' Send_attachment: Mail attachment
You_id=split (You_account, "@",-1, vbTextCompare)
' Account and server separation
Ms_space = "http://schemas.microsoft.com/cdo/configuration/"
' This is a must, but can be assured that the matter will not be sent through Microsoft Mail
Set Email = CreateObject ("CDO.") Message ")
Email.from = You_account
' This must be the same as the email account
Email.to = Send_email
' Primary Mailing Address
If send_email2 <> "" Then
email.cc = Send_email2
' Alternate email address
End If
Email.subject = Send_topic
' Message subject
Email.textbody = Send_body
' Message content
If send_attachment <> "" Then
Email.addattachment send_attachment
' Mail attachments
End If
With Email.Configuration.Fields
. Item (ms_space& "sendusing") = 2
' Letter Port
. Item (ms_space& "smtpserver") = "smtp." &AMP;YOU_ID (1)
' SMTP server address
. Item (ms_space& "smtpserverport") = 25
' SMTP server port
. Item (ms_space& "smtpauthenticate") = 1
' Cdobasec
. Item (ms_space& "sendusername") = you_id (0)
' Your email account
. Item (ms_space& "sendpassword") = You_password
' Your email password
. Update
End With
Email.send
' Send mail
Set email=nothing
' Close component
Send_mail=true
' If there are no error messages, the send is successful or the send fails
If ERR Then
Err.Clear
Send_mail=false
End If
End Function

If Send_mail (wscript.arguments (0), wscript.arguments (1), wscript.arguments (0), "", "Database Plane backup", "See Attachment", WScript.Arguments (2)) =true Then
WScript.Echo "Send Success"
Else
WScript.Echo "Send Failed"
End If

Note: Use to modify the contents of the corresponding comments including four parameters and two mailbox-related

Directory and disk characters for bat

Mail.vbs directory and disk characters

And finally your email address and password, you can also modify the code sent to other mailboxes note that 126 of the already useful, do not exclude some other mailboxes.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.