MySQL backup and synchronization shell script

Source: Internet
Author: User
Tags mysql backup
#! /Bin/bash
# Backup ad dbserver svr122.16to svr12234
# Sip = 192.168.4.154
CD/usr/local/yicha/tools/cnshop/backup /;
Synchronize shell scripts. Original Author mr. Jin
========================================================== ========================================================== ===

Tables_list = 'table. list'
Tb_list = 'cat $ tables_list | grep-V "#"'

Echo 'date + % F' % t' dB cntrade backup start ........................ .............. '> cnshop_sys.log;

For tb_name in $ tb_list

Do
/Usr/local/MySQL/bin/mysqldump-H 192.168.0.2-uroot-proot -- Opt -- compress cnshop $ tb_name |/usr/local/MySQL/bin/MySQL-uroot-proot cnshop;
Echo 'date + % F' % t' "DB cntrade $ tb_name backup OK."> cnshop_sys.log;
Done

Echo 'date + % F' % t' dB cntrade backup finished !....................... ........... '> Cnshop_sys.log;

MySQL backup script ============================================ ====================================
#/Bin/sh
Lastday = 'date -- date = "1 day ago" + % Y-% m-% d'; # One day ago

If test $1
Then
Lastday = $1;
FI;

Username = "root ";
Password = "root ";
Table = "cnshop ";
Position = "/usr/local/yicha/backup/DB /";
Filename = $ table "." $ lastday ". SQL ";

/Usr/local/MySQL/bin/mysqldump-U $ username-p $ password -- skip-opt-r $ table> $ position $ filename;
# Here -- skip-OPT is used to remove the optimized locking capability.-R is used to include the stored procedure.
CD $ position;
Tar czvf $ FILENAME ". tgz" $

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.