1. 数据库备份
mysqldump -u root -p bb -ppasswd > /tmp/backup_debugdump.txt
2. 安装 sendmail:
sudo apt-get install sendmail
命令行测试发送邮件: echo “邮件正文” | mail -s 邮件主题 516333132@qq.com
3. 安装定时任务软件
sudo apt-get install cron
service cron restart
4. 编写定时执行脚本 /usr/bin/backup_db.sh:
echo `date` >> /tmp/cron.log
mysqldump -u root -p bb -ppasswd > /tmp/backup_debugdump.txt
echo “数据库备份” | mail -s 数据库备份 -a /tmp/backup_debugdump.txt 516333132@qq.com
5. 编辑定时任务, 5分钟执行一次 /usr/bin/backup_db.sh
# m h dom mon dow command
*/5 * * * * /usr/bin/backup_db.sh
离线
# m h dom mon dow command
*/59 * * * * /usr/bin/backup_db.sh
奇怪了,以上配置,会在59分和00分都执行一次:
root@ubuntu:~# cat /tmp/cron.log
Wed Dec 26 19:59:01 EST 2018
Wed Dec 26 20:00:02 EST 2018
Wed Dec 26 20:59:01 EST 2018
Wed Dec 26 21:00:02 EST 2018
离线
支持下晕哥。
CS品牌SD NAND , ATO 小容量SLC/SPI NAND/MCP. T:13691982107,Q:2852826868
离线
mail 命令没有搞定发件人, 继续试一试 sendmail:
dbus-daemon --system
hostnamectl set-hostname whycan.cn
sendmail -t -f'noreply@whycan.cn' << EOF
From: noreply@whycan.cn
Sender:noreply
To:admin@whycan.cn
Cc:516333132@qq.com
Subject: 挖坑网测试邮件
----------------------------------
This is the mail content ...
debugdump
挖坑网发送邮件
---------------------------------
EOF
离线
mail 命令所有的参数都在这里: http://manpages.ubuntu.com/manpages/bionic/man1/bsd-mailx.1.html
ds and backwards, or simply enter a message number to
move directly.
Disposing of mail
After examining a message you can delete (d) or reply (r) to it. Deletion causes the mail
program to forget about the message. This is not irreversible; the message can be undeleted
(u) by giving its number, or the mail session can be aborted by giving the exit (x) command.
Deleted messages, however, will usually disappear, never to be seen again.
Specifying messages
Commands such as print and delete can be given a list of message numbers as arguments to
apply to a number of messages at once. Thus delete 1 2 deletes messages 1 and 2, while
delete 1-5 deletes messages 1 through 5.
Messages may also be selected using one of the following categories:
* all messages
$ last message
:d deleted messages
:n new messages
:o old messages
:r read messages
:u unread messages
Thus the command top, which prints the first few lines of a message, could be used in top *
to print the first few lines of all messages.
Replying to or originating mail
You can use the reply command to set up a response to a message, sending it back to the
person who it was from. Text you then type in, up to an end-of-file, defines the contents
of the message. While you are composing a message, mail treats lines beginning with the
tilde (‘~’) character specially. For instance, typing ~m (alone on a line) will place a
copy of the current message into the response, right shifting it by a single tab-stop (see
the indentprefix variable, below). Other escapes will set up subject fields, add and delete
recipients to the message, and allow you to escape to an editor to revise the message or to
a shell to run some commands. (These options are given in the summary below.)
Ending a mail processing session
You can end a mail session with the quit (q) command. Messages which have been examined go
to your mbox file unless they have been deleted, in which case they are discarded.
Unexamined messages go back to the post office (see the -f option above).
Personal and system wide distribution lists
It is also possible to create personal distribution lists so that, for instance, you can
send mail to “cohorts” and have it go to a group of people. Such lists can be defined by
placing a line like
alias cohorts bill ozalp jkf mark kridle@ucbcory
in the file .mailrc in your home directory. The current list of such aliases can be
displayed with the alias command in mail. System wide distribution lists can be created by
editing /etc/aliases, (see aliases(5)); these are kept in a different syntax. In mail you
send, personal aliases will be expanded in mail sent to others so that they will be able to
reply to the recipients. System wide aliases are not expanded when the mail is sent, but
any reply returned to the machine will have the system wide alias expanded as all mail goes
through an MTA.
Recipient address specifications
Recipient addresses (any of the “To”, “Cc” or “Bcc” header fields) are subject to expansion
when the expandaddr option is set.
An address may be expanded as follows:
· An address that starts with a pipe (‘|’) character is treated as a command to run.
The command immediately following the ‘|’ is executed with the message as its
standard input.
· An address that starts with a ‘+’ character is treated as a folder.
· An address that contains a ‘/’ character but no ‘!’, ‘%’, or ‘@’ characters is also
treated as a folder.
· If none of the above apply, the recipient is treated as a local or network mail
address.
If the expandaddr option is not set (the default), no expansion is performed and the
recipient is treated as a local or network mail address.
Character sets and MIME
Generally mail does not handle neither different character sets nor any other MIME feature.
Especially it does not perform any any conversions between character sets while displaying
or sending mails.
Starting from April 2017, however, as a Debian extension this version of mail adds a few
MIME headers to every outgoing mail in order to indicate that the mail is sent as 8-bit
plain text data that uses character set encoding detected from the current locale(7)
settings. The -a command-line option can be used to override those headers, for example:
$ mail -a 'Content-Type: text/plain; charset="ISO-8859-1"'
sets header indicating legacy character encoding.
Network mail (ARPA, UUCP, Berknet)
See mailaddr(7) for a description of network addresses.
mail has a number of options which can be set in the .mailrc file to alter its behavior;
thus set askcc enables the askcc feature. (These options are summarized below.)
其中 -r 参数就是发件人地址了.
这个命令可以设置发件人:
echo “邮件正文” | mail -s 邮件主题 -r noreply@whycan.cn 516333132@qq.com
如果要显示发件人名就这样:
echo “邮件正文” | mail -s 邮件主题 -r "noreply@whycan.cn(无需回复)" 516333132@qq.com
离线
找到一个脚本,可以用来打包一天内更新的文件:
https://stackoverflow.com/questions/848293/shell-script-get-all-files-modified-after-date/848323
find . -mtime -1 | xargs tar --no-recursion -czf myfile.tgz
再配合前面的 mail 命令, 配合cron非常轻松完成网站数据库和文件定时备份了
离线
sudo apt-get install sendmail mailutils -y
echo “邮件正文” | mail -s 邮件主题 -r noreply@xxx.com yyyyyyy@qq.com
为何我的阿里云服务器安装 sendmail 之后, 使用mail命令死活发不出邮件?难道是被锁住了吗?如何解锁呢?
但是用搬瓦工可以哦。
离线
厉害。。。
离线
定时备份,防患于未然
离线
感谢分享!向大佬们学习!!
离线
备份文件多大呀!时间长了,邮箱会不会爆掉,
离线
这个功能非常好啊
离线
不会,连续两年每小时备份一次数据163和qq邮箱都没有爆。
QQ邮箱有那种无限容量
离线
坛主,论坛什么时候考虑支持下 Markdown呀。
离线
备份文件多大呀!时间长了,邮箱会不会爆掉,
哎呀,96G了, 我这个126邮箱就爆了, 以前能找到扩容的按钮,现在找不到了, 貌似要升级VIP才行。
离线
https://whycan.cn/files/members/3438/2020-04-25_085631.png
哎呀,96G了, 我这个126邮箱就爆了, 以前能找到扩容的按钮,现在找不到了, 貌似要升级VIP才行。
QQ邮箱有那种无限容量,可以看看,扩容一段时间后可以再次扩容,直到无限容量
离线