Shell script, sub-database plus table backup for MySQL databases

Source: Internet
Author: User

[Email protected] wyb]#CatTable_backup.SH #!/bin/Bashflag=0User=Rootpass=Testmysql-u$user-p"$pass"-E"show databases;"&>/dev/NULL[ $? -ne0] && read-p"Mysql does not running,start it? (' Echo-e"\033[32myes/no\033[0m"`):"Choice && flag=1[[ "Choice"-eq"Yes"]] && service mysqld start &>/dev/NULL&& flag=0[$flag-eq1] && exit2Database= ' Mysql-u$user-p$pass-e"show databases;"|sed1d|grep-V'Schema'`Echo-E"\033[32m==================backup start=====================\033[0m" forIinch$database DoTables= ' Mysql-u$user-p"$pass"-E"Use $i; show tables;"|sed1d ' forJinch$tables Domysqldump-u$user-p"$pass"-B--databases $i--tables $j >/tmp/${i}-${j}-'Date+%F '. SQL [$? -eq0] &&Echo$i $j OK >>/tmp/table.log| |Echo$i $j failed >>/tmp/Table.log [$? -eq0] &&Echo-E"$i $j \033[32mok\033[0m"||Echo-E"$i $j \033[31mfailed\033[0m"   Done DoneEcho-E"\033[32m===================backup stop=======================\033[0m"[email protected] wyb]# bash table_backup.SH==================backup start=====================MySQL columns_priv okmysql db okmysql func okmysql help_category okmysql help_keyword okmysql help_relation Okmysql He Lp_topic okmysql host okmysql proc Okmysql procs_priv okmysql tables_priv okmysql time_zone okmysql Time_zone_leap_second Okmysql time_zone_name okmysql time_zone_transition okmysql time_zone_transition_type okmysql user OK===================backup stop=======================[[Email protected] wyb]# CD tmp-bash:cd:tmp:no suchfileor Directory[[email protected] wyb]# CD/Tmp[[email protected] tmp]#lsA.log MySQL-help_category- .- the- -. SQL mysql-tables_priv- .- the- -. SQL table.logdashazi123.SHmysql-help_keyword- .- the- -. SQL mysql-time_zone- .- the- -. SQL Vmwaredndkeyring-cmzniy mysql-help_relation- .- the- -. SQL mysql-time_zone_leap_second- .- the- -. SQL vmware-rootmapping-root mysql-help_topic- .- the- -. SQL mysql-time_zone_name- .- the- -. SQL vmware-root-1723735141MySQL-columns_priv- .- the- -. SQL mysql-host- .- the- -. SQL mysql-time_zone_transition- .- the- -. SQL vmwaretools-9.6.2-1688356.Tar. Gzmysql-db- .- the- -. SQL mysql-proc- .- the- -. SQL mysql-time_zone_transition_type- .- the- -. SQL vmware-tools-Distribmysql-func- .- the- -. SQL mysql-procs_priv- .- the- -. SQL mysql-user- .- the- -. Sql[[email protected] tmp]#lsmysql*MySQL-columns_priv- .- the- -. SQL mysql-help_topic- .- the- -. SQL mysql-time_zone_leap_second- .- the- -. Sqlmysql-db- .- the- -. SQL mysql-host- .- the- -. SQL mysql-time_zone_name- .- the- -. Sqlmysql-func- .- the- -. SQL mysql-proc- .- the- -. SQL mysql-time_zone_transition- .- the- -. Sqlmysql-help_category- .- the- -. SQL mysql-procs_priv- .- the- -. SQL mysql-time_zone_transition_type- .- the- -. Sqlmysql-help_keyword- .- the- -. SQL mysql-tables_priv- .- the- -. SQL mysql-user- .- the- -. Sqlmysql-help_relation- .- the- -. SQL mysql-time_zone- .- the- -. Sql[[email protected] tmp]#Cattable.log mysql columns_priv okmysql db okmysql func okmysql help_category okmysql help_keyword okmysql help_relation Okmysql help_topic okmysql host okmysql proc Okmysql procs_priv okmysql tables_priv okmysql time_zone okmysql time_zone_l Eap_second okmysql time_zone_name okmysql time_zone_transition okmysql time_zone_transition_type okmysql user Ok[[email Protected] tmp]#

Shell script, sub-database plus table backup for MySQL databases

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.