MySQL logical backup mysqldump

Source: Internet
Author: User

A small script that makes logical backups with mysqldump

For small data volume backup, whole library, by date, by library, by table, classification

# date-s "2015/01/01" && bash mybackup.sh

#! /bin/bash# using mysqldump for logical backup # directory structure/backup/date # Delete old backup directory every 7 days db_backup_root= "/backup" today= ' date +%y%m%d ' Old_backup_ Dir= ' date-d '-7 Day "+%y%m%d ' db_user=" root "db_passwd=" Geekoo "sock= ' mysql-u$db_user-p$db_passwd-e" show variables Like '%sock% ' | Grep-v Variable_name | awk {' Print $ '} ' mysql_client= ' which MySQL ' mysqldump_client= ' which mysqldump ' xmysql= ' $mysql _client-s $sock-u$db_ USER-P$DB_PASSWD "xmysqldump=" $mysqldump _client-s $sock-u$db_user-p$db_passwd "If [-D $old _backup_dir]; Thenecho "Delete old backup $old _backup_dir" RM-RF $old _backup_dirfiif [!-D $today]; Thenmkdir-p $db _backup_root/$todayfi $xmysql-e "show databases;" | Grep-ve "(Database|_schema)" > $db _backup_root/$today/db_listwhile read Dbnamedo echo $dbnameif [!-D $db _backup_root /$today/$dbname]; Thenmkdir-p $db _backup_root/$today/$dbnamefi $xmysql-e "use $dbname; Show tables; "| Grep-v tables_in > $db _backup_root/$today/$dbname/table_listwhile read Tablenamedoecho $tablename $xmysqldump $ dbname$tablename-R--events--triggers > $db _backup_root/$today/$dbname/$tablename. Sqldone < $db _backup_root/$today/ $dbname/table_listdone < $db _backup_root/$today/db_list

MySQL logical backup mysqldump

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.