Back up some MySQL tables and upload them to the specified FTP server directory

Source: Internet
Author: User

Security Code: Indifferent Childe


A few days ago, the leader arranged a task to write a script back up some of the tables in a MySQL database, and to upload the backed up files to an FTP server, so the following script


#!/bin/bash#filename:mysqldump.sh#function:backup a part of tables from mysql  databases then package it and put it to ftp server#author: forgotten love#date:2016-12-15basedir=/root/backupcurdate=$ (/bin/date +%y%m%d) FTPIP= 192.168.7.500fullname=${basedir}/mysqldump_${curdate}.tar.gzdestdir=/ops/backuplocal_filename=$ (/bin/basename   $FULLNAME) destfile=${destdir}/$local _filenameftpput () {ftp -i -n <<eofopen $ ftpipuser username passwordbinpassivecd  $DESTDIRput   $FULLNAME   $DESTFILEquitEOF} #put   $FULLNAME   $DESTFILE #backup all tablesecho  "################################## backuping tables##################################### "for tablename in bond  institution;domysqldump -uroot -pgamma23$ ss_product  $tablename  > ${basedir}/ ${tablename}_$curdatedone#backup a part of tablesmysqldump -uroot -pgamma23$ ss_product qb_bond_deal -w  "Create_ Time " > ${basedir}/qb_bond_deal_$curdateecho " ################################# #packaging  file####################################### "cd  $basedir/bin/tar zcf mysqldump_${curdate}. tar.gz [biq]*_$curdateecho  "################################# #putting  file##################### #################### "if [ -f mysqldump_${curdate}.tar.gz ];thenftpput &>/dev/ nullfiecho  "##################################  finished  ########################### ##############"


This script is intended for the Redhat family of operating systems, with the need to change the appropriate FTP server address, FTP user name, FTP user password, and the appropriate backup directory and files to upload to the FTP directory for medium information. In addition, you need to ensure that the script FTP, mysqldump and other commands in the system already exist in order to execute this script, otherwise it will be an error.

This article from "Indifferent Bo" blog, reproduced please contact the author!

Back up some MySQL tables and upload them to the specified FTP server directory

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.