Linux database backup and share _linux Shell via FTP upload script

Source: Internet
Author: User

Copy Code code as follows:

#!/bin/bash

#author: 505056357@qq.com

echo "Backup Job Start"

#设置要备份的网站目录, that is, the root directory of the Web site

File=/home/wwwroot/default

#设置本地备份目录, for storing the packaged files

backpath=/home/wwwroot/bkdata/

Dbuser=root

#数据密码, remember to enclose the entire password in single quotes and double quotes if the cipher has single quotes, hehe

Dbpwd= ' 123456 '

Dbname=car

domain=192.168.0.187

User=ftpuser

Userpwd= ' 123456 '

bkdate=$ (Date +%y%m%d)

Sqlfile_sql=${dbname}_${bkdate}.sql

Sqlfile_gz=${dbname}_${bkdate}.tar.gz

sqlfp=${backpath}${bkdate}/$sqlfile _sql

If [-E $backpath ${bkdate}]

Then

Echo $backpath is exists.

Else

Mkdir-p $backpath ${bkdate}

Fi

#执行数据库备份,/apps/mysql/bin/mysqldump Modify the path to your actual environment

/apps/mysql/bin/mysqldump-u $dbuser-p$dbpwd $dbname > ${SQLFP}

#对备份之后的数据库文件压缩, or compress directly by adding parameters at the time of database backup

Tar zcf $backpath ${bkdate}/$sqlfile _gz-c ${backpath}${bkdate} ${sqlfile_sql}

#删除未压缩SQL的文件

Rm-f ${SQLFP}

#生成的文件名格式: Web_ Site Directory name _20130419.tar.gz

Fn=web_${file##*/}_${bkdate}.tar.gz

Tar zcf $backpath ${bkdate}/$fn-C ${file%/*} ${file##*/}

#以下操作为FTP自动连接并把本地文件上传到异地服务器上

/usr/bin/lftp ${domain} << End

User ${user} ${userpwd}

LCD ${backpath}

Mirror-r ${bkdate}

Exit

End

echo "Backup Job done"

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.