MySQL database export compression and save to the specified location backup script

Source: Internet
Author: User
Tags mkdir


A script is used to export all MySQL databases and save them to a specified location.
The contents are as follows:

The code is as follows Copy Code

#!/bin/bash
############################################
#
# This is a MySQL database backup script
# One at a time to export all the database and GZ compressed save
# ccshaowei#gmail.com
# 2013/05/08
# http://www.111cn.net#
############################################
# Backup Directory
Backdir=/home/shaowei/dbbak
# Database Login User Name
Dbuser= ' Dbusername '
# Database Login Password
dbpass= ' dbpasswd '
# database location is usually/var/lib/mysql
dblist=$ (ls-p/var/lib/mysql | grep/| tr-d/)
################ Configuration End #################
today=$ (Date +%y%m%d)
mkdir $backdir
mkdir $backdir/$today
For dbname in $dblist
######################################## #如果不需要显示压缩比, remove the-v parameter after gzip
Do Mysqldump-u$dbuser-p$dbpass $dbname | Gzip-v > $backdir/$today/$dbname-$today sql.gz
echo $dbname ' OK ' #如果需要他默默的运行, comment out this line
Done


The run result is to save all the databases to the backup directory/today's date/xxx.sql.gz

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.