MySQL Backup script-mysqldump

Source: Internet
Author: User
Tags disk usage mysql backup

Background: Full Library backup

Backup process:

1. Generate DB list, write DB name to file

2. Define the backup function and write the result to the SQL file

3. Compress files to reduce disk usage

4. Set the number of days to retain, periodically delete the n days before

5. Read the DB list file through the For loop, mysqldump

1#!/bin/Bash2 3port='5001'4Passwd='Admin'5Socked="/data/socket/mysql${port}.sock"6backup_file='/data/mysqldata/backup'7backup_save_days='2'8 9cmd1='show databases;'TenTime= 'Date+%y%m%d_%h%m%S ' OneEvery_day_backup_dir="${backup_file}/${time}_backup" Adb_list="${every_day_backup_dir}/db_list.txt" -  -#function: check_db ===>Db_list.txt the check_db () - { -     mkdir-PV ${every_day_backup_dir} >>/dev/NULL -     Touch${db_list} &&chmod 755${db_list} &&Chown-R mysql.mysql ${db_list} +/USR/LOCAL/MYSQL/BIN/MYSQL-UADMIN-P${PASSWD}-S ${socked}-nbe"${CMD1}"|grep-V'Information_schema\|performance_schema\|mysql'>${db_list} -  + } A  at#function: backup_db ===>Xx.sql - backup_db () - { -/USR/LOCAL/MYSQL/BIN/MYSQLDUMP-UADMIN-P${PASSWD}-S ${socked} $1>> ${every_day_backup_dir}/$1. SQL - } -  in#function: Tar_file ===>xx.Tar. GZ - Tar_file () to { + CD ${backup_file} -     Tar-CF 'Date+%y%m%d_%h%m%s '.Tar. GZ ${time}_backup the     RM-FR ${time}_backup * } $ Panax Notoginseng#function: Delete xx.Tar. GZ: <before n days> - Delete_file () the { + CD ${backup_file} A/usr/bin/Find-name"*.tar.gz"-mtime +${backup_save_days}-execRM {} \; the } +  - # main_process $#1 $ check_db -  -#2 the Cat${db_list}| whileRead Line -  Do Wuyioldifs=${ifs} the backup_db ${line} -ifs=${oldifs} Wu     Sleep  - -  Done About  $#3  - Tar_file -  -#4Delete XX.Tar. Gz:before N Days A  +Delete_file ${backup_save_days}

MySQL Backup script-mysqldump

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.