Linux automatic daily backup files and database upload FTP space

Source: Internet
Author: User

To install the email sending component:

Yum Install SendMail Mutt
vi/root/autobackuptoftp.sh
#!/bin/bashmysql_user=root                               #mysql用户名MYSQL_PASS = 123456                        #mysql密码 [email protected]                   #数据库发送到的邮箱FTP_USER =cat                                 #ftp用户名FTP_PASS =123456                          # FTP Password ftp_ip=192.168.2.100                            #ftp地址FTP_backup =backup                             #ftp上存放备份文件的目录, this is going to have to own the FTP web_data=/home/www                           # The site data to be backed up # defines the name of the database and the name of the old database databakname=data_$ (date + "%y%m%d"). tar.gzwebbakname=web_$ (date +%y%m%d). tar.gzolddata=data_$ (date -d -5day + "%y%m%d"). tar.gzoldweb=web_$ (date -d -5day + "%y%m%d"). tar.gz# Delete the data rm -rf /home/backup/data_$ (date -d -3day + "%Y%m%d") 3 days ago. tar.gz  /home/backup/web_$ (date -d -3day + "%y%m%d"). tar.gzcd /home/backup# Export the database, A database a compressed file for db in  '/usr/local/mysql/bin/mysql -u$mysql_user -p$mysql_pass -b  -N -e  ' Show databASES '  | xargs ';d o     (/usr/local/mysql/bin/mysqldump -u$mysql_user -p$ mysql_pass ${db} | gzip -9 - > ${db}.sql.gz) done# compress the database file to a file tar  zcf /home/backup/$DataBakName  /home/backup/*.sql.gzrm -rf /home/backup/*.sql.gz# Send database to email, if the database is compressed too large, please comment this line echo  "topic: Database Backup"  | mutt -a /home/backup/$DataBakName   -s  "Content: Database Backup"   $MAIL _to# compress website data tar zcf /home/backup/$WebBakName   $WEB _data# upload to FTP space, Delete FTP space 5 days ago Data ftp -v -n  $FTP _ip << enduser  $FTP _user  $FTP _passtype  binarycd  $FTP _backupdelete  $OldDatadelete   $OldWebput   $DataBakNameput  $ Webbaknamebyeend

To add execute permissions to the script:

chmod +x/root/autobackuptoftp.sh


Automate daily operation with system crontab:

Crontab-e


Enter the following:


XX * * * */root/autobackuptoftp.sh


00 00 is time/hour, can be modified by itself, for example: 30 12 * * *, that is, 12.30 runs the script every day.


Linux automatic daily backup files and database upload FTP space

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.