Linux backup MySQL-automatically send to the specified mailbox via email

Source: Internet
Author: User
1. the command line mail tool in muttLinux can be used to receive and send mails to the mail server in sendmailpostfixLinux. All mails are sent from the local machine.

1. the required software mutt command line mail tool in Linux can be used to receive and send emails to sendmail/postfix mail servers in Linux. All emails are sent from the local machine.

1. Required Software

The command line email tool in mutt Linux, which can be used to receive and send emails.

Sendmail/postfix on the mail server in Linux, all emails are sent from the Local Machine

MySQL database backup program

2. mutt parameter Introduction

- Attachment

-S Topic

Example:

Echo "Hello, have a good time! "| Mutt-a/etc/passwd-s" Linux emails with attachments "cc2@cc2.cc

(Echo print content for the mail body, send Password File passwd to the mailbox cc2@cc2.cc)

3. Script

Database Name of the test backup:

Scriptdev2 realmd mmfpm mangos characters

View the character set used by the database

Show variables like "char % ";

Utf8

Create backup script

Vi/root/send-mysql-data.sh

#! /Bin/bash

# Power by hugwww 2009-4-11

# Set time format

Date = 'date-d "% m" date-d today + "% Y-% m-% d-% H: % M "'

Echo $ date

# Defining Arrays

Db_array = (scriptdev2 realmd mmfpm characters mangos)

# Retrieve the number of arrays without elements

LenArray =$ {# db_array [@]}

# Listing array elements cyclically

I = 0

While [$ I-lt $ lenArray]

Do

# Backup

Mysqldump-uroot-ppassw0rd -- default-character-set = utf8 -- opt -- extended-insert = false \

-- Triggers-R -- hex-blob-x $ {db_array [$ I]}>/opt/db-backup/everyday/$ {db_array [$ I]}-$ date. SQL;

# Echo $ {db_array [$ I]}

Let I ++

Done

# Compressing all SQL files into one file

Tar cvzf/opt/db-backup/mysql-data-1_date.tar.gz/opt/db-backup/everyday/* $ date. SQL

# Send the backup file to your mailbox

Echo "$ date database backup file" | mutt-a/opt/db-backup/mysql-data-.tar.gz-s "mangos database backup" cc2@cc2.cc

Echo "$ date backup succeeded and sent to the specified email address">/opt/db-backup/backup. log

Exit

Complete

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.