Websites and databases are automatically backed up to email

Source: Internet
Author: User
Today, according to the tutorial on the Internet, I changed it to only sending it to my mailbox, because there is no ftp space for backup. My operations are as follows: 1. install yum-yinstallsendmailmutt for mutt. 2. configure cp/etc/Muttrc/root /. muttrc edit/root /. mu... today, according to the tutorial on the Internet, I changed it to only sending it to my mailbox, because there is no ftp space for backup. My operations are as follows:
 
1. install mutt
 
Yum-y install sendmail mutt
 
II. configuration information
 
Cp/etc/Muttrc/root/. muttrc
 
Edit/root/. muttrc to modify the configuration file,
 
Set charset = "UTF-8 ″
 
Set rfc2047_parameters = yes
 
Set envelope_from = yes
 
Set use_from = yes
 
Set from = admin@xusy.co
 
Set realname = "xusy"
 
III. backup script
 
#! /Bin/bash
# Start from here
MYSQL_USER = root # mysql username
MYSQL_PASS = 123456 # mysql password
MAIL_TO = 888888888@qq.com # mailbox to which the database is sent
WEB_DATA =/home/www # Website data to be backed up
# The point you want to modify ends from here
 
# Define the database name and old database name
DataBakName = Data _ $
WebBakName = Web _ $
# Delete data from the local device three days ago
Rm-rf/home/backup/Data _ $
Cd/home/backup
# Exporting a database, a database, and a compressed file
For db in '/usr/local/mysql/bin/mysql-u $ MYSQL_USER-p $ MYSQL_PASS-B-N-e 'show databases' | xargs'; do
(/Usr/local/mysql/bin/mysqldump-u $ MYSQL_USER-p $ MYSQL_PASS $ {db} | gzip-9-> ${db#. SQL .gz)
Done
# Compressing a database file into a file
Tar zcf/home/backup/$ DataBakName/home/backup/*. SQL .gz
Rm-rf/home/backup/*. SQL .gz
# Compressing website data
Tar zcf/home/backup/$ WebBakName $ WEB_DATA
# Send the database to Email. if the database size is too large after compression, comment out this line.
Echo "Topic: database and website backup" | mutt-s "content: database and website backup "-a/home/backup/$ DataBakName-a/home/backup/$ WebBakName $ MAIL_TO
 
END
 
4. Upload to root and Grant write permission
 
Chmod + x/root/AutoBackup. sh
 
5. use the system crontab to automatically run on a daily basis
 
Crontab-e
 
Input: 00 00 ***/root/AutoBackup. sh
 
Here, 00 is the time minute/hour, which can be modified by yourself. for example, if it is 30 12 ***, this script is run 12.30 every day.
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.