Using the shell to back up sites and databases

Source: Internet
Author: User
Tags bz2

#/bin/bash

backupath=/opt/backup/

webpath=/usr/local/apache2/htdocs/

Date= ' Date +%y%m%d '

webbakfile=web${date}.tar.bz2

dbfile=db${date}.tar.bz2

Dbuser= ' Root '

Dbpassword= ' 123 '

ftpserver=192.168.1.107

Ftptargetpath= ' Ftp/backup '


CD $WebPath

Pwd


Tar jcf $WebBakFIle * | MV $WebBakFIle $BackuPath

For DB in ' Mysql-u$dbuser-p$dbpassword-b-n-e ' show databases;

Do

Mysqldump-u$dbuser-p$dbpassword--single-transaction $db > ${db}.sql


Done

For sqlfile in ' ls-l | grep ". sql" | awk ' {print $8} '

Do

Tar jcf $DBFile $sqlfile | MV $DBFile $BackuPath

Done


CD $BackuPath

Pwd

FTP-V-N $FTPserver << END

User LBX qwe123

Bin

CD $FtpTargetPath

Ls-l

Put $DBFile

Put $WebBakFIle

Bye

END



File was successfully backed up: 650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4D/56/wKiom1RPrLegsJB1AAOgZMO02CM727.jpg "title = "2014-10-28 22:47:52 screen. png" alt= "wkiom1rprlegsjb1aaogzmo02cm727.jpg"/>



Automatic backup every night 4 o'clock in the morning:

[Email protected] opt]# crontab-l

0 4 * * * bash/opt/echo.sh


This article is from the "Dragon Love Xue qi" blog, please make sure to keep this source http://dragon123.blog.51cto.com/9152073/1569011

Using the shell to back up sites and databases

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.