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