我创建了一个脚本,每天晚上在我的Linux服务器上运行,它使用mysqldump将我的每个MySQL数据库备份到.sql文件,并将它们打包成一个压缩的.tar文件。我想完成的下一步是通过电子邮件将tar文件发送到远程电子邮件服务器以确保安全。我已经能够通过管道备份文本文件到mailx发送原始脚本正文的电子邮件,就像这样:

$ cat mysqldbbackup.sql | mailx backup@email.example

Cat回显备份文件的文本,该文本通过管道输入mailx程序,并将收件人的电子邮件地址作为参数传递。

虽然这实现了我所需要的,我认为它可以更好的一步,有任何方法,使用shell脚本或其他方式,将压缩的.tar文件作为附件发送到外发电子邮件消息?这将避免处理包含标题数据和经常有换行问题等非常长的电子邮件。


当前回答

Metamail有metasend工具

metasend -f mysqlbackup.sql.gz -t backup@email.com -s Backup -m application/x-gzip -b

其他回答

我通常只在RHEL上使用mail命令。我试过mailx,它很有效率。

mailx -s "Sending Files" -a First_LocalConfig.conf -a
Second_LocalConfig.conf Recipient@myemail.com

This is the content of my msg.

.

我使用SendEmail,它就是为这个场景创建的。它是为Ubuntu打包的,所以我认为它是可用的

sendemail -f sender@some.where -t receiver@some.place -m“这是你的文件!”-a file1.jpg file2.zip

http://caspian.dotconf.net/menu/Software/SendEmail/

另一种选择- Swaks (SMTP的瑞士军刀)。

swaks -tls \
    --to ${MAIL_TO} \
    --from ${MAIL_FROM} \
    --server ${MAIL_SERVER} \
    --auth LOGIN \
    --auth-user ${MAIL_USER} \
    --auth-password ${MAIL_PASSWORD} \
    --header "Subject: $MAIL_SUBJECT" \
    --header "Content-Type: text/html; charset=UTF-8" \
    --body "$MESSAGE" \
    --attach mysqldbbackup.sql

对我来说,最近的路是

file=filename_or_filepath;uuencode $file $file|mail -s "optional subject" email_address

举个例子

file=your_sql.log;gzip -c $file;uuencode ${file}.gz ${file}|mail -s "file with magnets" ph.gachoud@gmail.com

好的部分是我可以用Ctrl+r收回它来发送另一个文件…

不是一种发送电子邮件的方法,但你可以使用在线Git服务器(例如Bitbucket或类似的服务)。

通过这种方式,你可以使用git push命令,所有版本都将以压缩和有组织的方式存储。