MySQL backup and recovery via shell script, for in Process control

Source: Internet
Author: User

 #!/bin/bash my_date= ' Date +%y%m%d ' my_time= ' date +%h%m ' my_ from 3306 Backup database, restored to 3307 database, via for-in process control for shell scripts date_yesterday= ' Date +%y%m%d--date= ' 1 days ago '  echo '----------------------------------------------------' echo "$my _date $my _time"  backup_dir= "/data/backup3307/${my_date}" mkdir-p ${backup_dir}echo "db backup dir: ${ Backup_dir} " dbs=" Data1 data2 data3 data4 "for DB in ${dbs}doecho" ${db} backup start ... "echo" $my _date $my _time "file = "${backup_dir}/${db}_${my_date}.sql" mysqldump--login-path=backup--single-transaction--set-gtid-purged=off-- Opt--triggers--routines--events ${db} > ${file}size= ' Ls-lh ${file}|awk ' {print $} ' echo ' Size: ${size} ' echo ' ${db} Backup end. "echo" $my _date $my _time " echo" ${db} restore Start ... "MySQL--login-path=restore-e" CREATE DATABASE ${db}_$my_ Date_yesterday DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci; " MySQL--login-path=restore "${db}_$my_date_yesterday" < ${file}echo "${db} Restore end." echo "$my _date $my _time "echo" gzip ${file} "gzip ${file}done # delete old backup dataold_date= ' date +%y%m%d-d ' 5 days ago ' RM-RF/ Data/backup3307/${old_date} for in cycle example:  #!/bin/sh s= "a b C"  for I in $sdoecho "I am $i" done  Execution result:  #./for_in.shi is-ai is-bi is-c

MySQL backup and recovery via shell script, for in Process control

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.