Nodejs a timed call to the shell script to back up the database and log files and send them to the mailbox

Source: Internet
Author: User
Tags auth

install MAILX, rely on it to send mail

yum install mailx

Editing a configuration file

vim /etc/mail.rc #添加如下内容set [email protected]set smtp=smtp.163.comset [email protected]set smtp-auth-password=xxxset smtp-auth=login---说明from:对方收到邮件时显示的发件人smtp:指定第三方发邮件的smtp服务器地址set smtp-auth-user:第三方发邮件的用户名set smtp-auth-password:用户名对应的密码,有些邮箱填的是授权码smtp-auth:SMTP的认证方式,默认是login,也可以改成CRAM-MD5或PLAIN方式

Linux script File source code (note must be directly in the Linux system directly edit, or create a file suffix will have a question mark!!!) ):

#!/bin/bashecho "开始"#备份数据库mysqldump -uroot -p数据库密码 数据库名字 > /home/wwwroot/bak/`date +%Y_%m_%d`.sqlecho ‘备份数据库完毕‘ #备份日志(将日志文件复制到备份数据库的文件夹里)oldlog=/home/wwwlogst/web.lognewlog=/home/wwwroot/bak/`date +%Y_%m_%d`.logcp ${oldlog}  ${newlog} echo "" > ${oldlog}echo ‘备份日志完毕‘ #打包文件夹name= /home/wwwroot/`date +%Y_%m_%d_%H_%M_%s`.zip old= /home/wwwroot/bakzip -r ${name} ${old} echo ‘打包文件夹完毕‘#发送邮件echo `date +%Y_%m_%d数据库备份` | mail -s `date +%Y_%m_%d备份邮件` -a  ${name} 你的邮箱@qq.com echo ‘发送邮件完毕‘echo "全部完毕"

Nodejs the source code of the timed call script

/** * Created by Administrator on 2018/2/25 0025. */var https = require(‘http‘);var schedule = require(‘node-schedule‘);var exec = require(‘child_process‘).exec;var cmdStr = ‘sh /home/wwwroot/myemail.sh‘;//这里面写你要执行的命令就行var rule = new schedule.RecurrenceRule();// rule.second = [0,10,20,30,40,50];//隔十秒rule.hour =23;rule.minute =55;rule.second =0;//每天23点55分执行var j = schedule.scheduleJob(rule, function(){exec(cmdStr, function(err,stdout,stderr){    console.log("已执行");});console.log(‘现在时间:‘,new Date());});

Nodejs a timed call to the shell script to back up the database and log files and send them to the mailbox

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.