网站备份脚本
建立脚本 /var/backups/create.sh
添加执行权限chmod +x create.sh
然后添加crontab定时任务
0 0 * * * /var/backups/create.sh
脚本文件如下
#! /bin/bash tDir=$(date '+%Y%m%d%H'); tDir="/var/backups/$tDir"; echo $tDir; if [ ! -d $tDir ];then mkdir $tDir; fi mysqldump -uroot -ppassword dbname > "$tDir/name.sql" mkdir "$tDir/source/" cp -r /var/www/op_system/app "$tDir/source/app" cp -r /var/www/op_system/config "$tDir/source/config" cp -r /var/www/op_system/public "$tDir/source/public" cp -r /var/www/op_system/resources "$tDir/source/resources" cp -r /var/www/op_system/.env "$tDir/source/.env" find /var/backups/* -maxdepth 0 -type d -mtime +15 |xargs rm -rf
转载请注明原处