CentOS6.3 use Shell to back up system files and implement mail delivery

Source: Internet
Author: User
Tags bz2 mkdir mysql backup backup

System Environment: CentOS6.3

Mutt:yum Default Source Installation

1. Install Mutt mail Client

# yum Install Mutt-y

2. Create a script

# vi/etc/rc.d/mail_to_bak_daily.sh

(Version i)

------------------------------------------------------------

#!/bin/bash

# =========================================================

# Please enter which separate directory you want to put the backup data in

Basedir=/backup/daily

# =========================================================

Path=/bin:/usr/bin:/sbin:/usr/sbin::/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin;

Export PATH

Export Lang=c

# define Database Information

User=root

passwd=123456

# define MySQL backup path

mysql_db_bak= $basedir/mysql_db_bak/$ (date +%f_%h%m)

[!-D "$mysql _db_bak"] && mkdir-p $mysql _db_bak

# define WWW backup path

www_src_bak= $basedir/www_src_bak/$ (date +%f_%h%m)

[!-D "$www _src_bak"] && mkdir-p $www _src_bak

# define message attachment path

Mail_attach_mysql= $mysql _db_bak/wordpress.sql

mail_attach_www= $www _src_bak/www.tar.bz2

# define message Headers

mail_subject= "Www.example.com_daily_backup"

# Note: The characters between the headings here can not have spaces, if there are spaces will be issued according to the name of the message, such as daily@www.example.com,backup@www.example.com This example of the following underlined instead

# define message Content

Mail_content=/tmp/mail_content.txt

Mail_code= "Send Mysql_bak and WWW_SRC to/at $ (date +%f_%h%m)"

# define email Addresses

Mail_address= "Test@example.com"

# 1. Backup MySQL (database directory in/usr/local/mysql)

Mysqldump-u $user-p$passwd--opt--skip-lock-tables--flush-logs--database wordpress > $mysql _db_bak/wordpress.sql

# 2. Back up www source code:

Cd/usr/local

tar-jpcf $www _src_bak/www.tar.bz2 www

# 3. Message body

Cd/tmp

echo $mail _code > $mail _content

# 4. Send Attachments

Cat $mail _content |mutt-s $mail _subject-a $mail _attach_mysql-a $mail _attach_www--$mail _address

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.