备份自己的网站源码

#! /bin/sh 


filename=backup_wkcto.com@$(date +%Y-%m-%d).zip
echo $filename
backupFile=/data/sites/wk/

zip -r $filename  $backupFile &&  mv $filename  /home/xiaozhao/

简单的切割日志

#!/bin/bash


LOG_ACCESS_PATH=/usr/local/openresty/nginx/logs/access_www.log
BASE_ACCESS_PATH=/root/backup_log/www_access/$(date -d yesterday +%Y%m)


if [ ! -d "$BASE_ACCESS_PATH" ]; then
mkdir -p $BASE_ACCESS_PATH
fi


BACKUP_ACCESS_FILE=$BASE_ACCESS_PATH/$(date -d yesterday +%d)_access_www.log

mv $LOG_ACCESS_PATH $BACKUP_ACCESS_FILE
touch $LOG_ACCESS_PATH



LOG_ERROR_PATH=/usr/local/openresty/nginx/logs/error_www.log
BASE_ERROR_PATH=/root/backup_log/www_error/$(date -d yesterday +%Y%m)


if [ ! -d "$BASE_ERROR_PATH" ]; then
mkdir -p  $BASE_ERROR_PATH
fi


BACKUP_ERROR_FILE=$BASE_ERROR_PATH/$(date -d yesterday +%d)_error_www.log

mv $LOG_ERROR_PATH $BACKUP_ERROR_FILE
touch $LOG_ERROR_PATH



kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid`

简单的备份数据库

# cat /opt/sh/backup_db.sh 
#!/bin/bash 
time=`date +%Y%m%d`
mysqldump --opt -u root dongli_www > /root/backup_db/bjpowernode_$time.sql
mysqldump --opt -u root wk> /root/backup_db/wkcto_$time.sql

cd    /root/backup_db &&  /root/backup_db/backup.php

用PHP清理大于一周的SQL文件

#! /bin/php
<?php
$dir=opendir('./');
$weekTime=strtotime(date('Y-m-d',time()).'-1 week');
while ($file=readdir($dir)){
    if($file=='.'||$file=='..' || $file=='bak') continue;
    $fileTime=strtotime(date('Y-m-d',filectime($file)));
    if($fileTime-$weekTime<0){
         $bool=unlink($file);
        if($bool) echo $file."删除成功\n";
    }
}

计划任务脚本crontab -e

30 1 * * * sh -x /opt/sh/backup_db.sh
50 1 * * *  sh -x /root/backup_log/backup_www_log
52 1 * * *  sh -x /root/backup_log/backup_skcto_log
54 1 * * *  sh -x /root/backup_log/backup_wkcto_log

1 */1 * * *   sh /usr/local/coreseek/script_index.sh
*/10 * * * *  sh /usr/local/coreseek/script_delta.sh
Last modification:May 18, 2023
如果觉得我的文章对你有用,请随意赞赏