Linux VPS scheduled backup website, database command sh

Source: Internet
Author: User
Tags vps webfile

VPS Scheduled BACKUP DATABASE command, save the following code as BACKSQL.SH, and then set the scheduled task to run.

cd/home/admin/Backup #切换到备份目录btimes=$(Date+%y%m%d%h%M) #定义备份时间agobtimes=$(Date-d-7day +%y%m%d%h%M) #定义删除七天前的备份RM-RF Allsql/vps_all_db_$agobtimes.Tar. GZ #删除操作 forDbinch'/usr/bin/mysql--user="Root"--password="123456"-b-n-E'SHOW DATABASES'|Xargs` Do(/usr/bin/mysqldump--user="Root"--password="123456"${DB} | /bin/gzip-9-> allsql/${db}.sql.gz) Done#遍列所有数据库并单个打包Tar-ZCF Allsql/vps7_all_db_$btimes.Tar. GZ Allsql/*. sql.gz #打包所有数据库为一个压缩包mysqlcheck-aao--auto-repair--user= "root"--password= "123456" #修复表echo "vps_all_db_$ Btimes.tar.gz "| Mutt [email protected]-a/home/admin/backupftp/allsql/vps_all_db_$btimes.tar.gz-s "vps_all_db_$btimes.tar.gz" # Send Backup to Mailbox Rm-rf allsql/*.sql.gz #删除单个数据库备份文件

The following is a scheduled backup site file sent to the FTP command, save the following code as BACKWEB.SH, and then set the scheduled task to run.

cd/home/admin/BackupmkdirWebfilebtime=$(Date+%y%m%d%h%M) Agobtime=$(Date-d-7day +%y%m%d%h%M)Tar-CVF Webfile/vps_web_$btime.Tar/home/admin/domainsbzip2-Z-9-F Webfile/vps_web_$btime.TarCD WebFileFTP-v-n127.0.0.1<<enduser ftpuser passwordtype binarycd webbackupput vps_web_$btime.Tar. Bz2delete vps_web_$agobtime.Tar. BZ2BYEENDCD .RM-R WebFile

Linux VPS scheduled backup website, database command sh

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.