Linux automatically backs up files and databases and uploads them to the specified remote FTP

Source: Internet
Author: User

Copy the following script directly to/root/backup.sh
[Email protected] ~]# chmod +x/root/backup.sh
[Email protected] ~]# CRONTAB-E
XX * * */root/backup.sh
[Email protected] ~]# service Crond restart
[Email protected] ~]# chkconfig--level 2345 Crond on

#!/bin/bash# the place you want to modify starts here mysql_user=root #mysql用户名MYSQL_PASS = #mysql密码FTP_USER = #ftp用户名FTP_PASS = #ftp密码FTP_IP = #ftp地址FTP_backup = #ftp上存放备份文件的目录, you need to build web_data=/home/wwwroot on the FTP first #本地要备份的网站数据 #你要修改的地方从这里结束 if [!-f/usr/bin/ftp]; Then yum install ftp-yfiif [!-d/home/backup]; Then MKDIR/HOME/BACKUPFI #定义数据库的名字和旧数据库的名字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 #删除本地3天前的数据rm-RF/ home/backup/data_$ (date-d -3day + "%y%m%d"). tar.gz/home/backup/web_$ (date-d -3day + "%y%m%d"). Tar.gzcd/home/backup # Export 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 '; Do (/usr/local/mysql/bin/mysqldump-u$mysql_user-p$mysql_pass ${db}-Q--skip-lock-tables | gzip-9-> ${DB}.SQL.G Z) done #压缩数据库文件为一个文件tar zcf/home/backup/$DataBakName/home/backup/*.sql.gzrm-rf/home/backup/*.sql.gz #压缩网站数据tar zcf/home/backup/$WebBakName $WEB _data #上传到FTP空间, delete ftp space 5 days ago Data ftp-v-N $ Ftp_ip << enduser $FTP _user $FTP _passtype binarycd $FTP _backupdelete $OldDatadelete $OldWebput $DataBakNameput $ Webbaknamebyeend

  

Linux automatically backs up files and databases and uploads them to the specified remote FTP

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.