#!/bin/bash # Daily BACKUP log file log_path= "/home/fdipzone/logs" # Log directory Backup_path= "/home/fdipzone/logs/bak" # Backup directory ex PIRE=30 # Backup file only retains 30 days function backup () {if [-d ' $log _path] && [d] $backup _ Path "]; Then for file in $ (find $log _path-maxdepth 1-name "*.log"-type f); Do copy $file did else echo "${log_path} or ${backup_path} NOT exists" fi} functi
On copy () {ofile=$1 dpath= "${backup_path}/$ (date-d yesterday +%y/%m/%d/)" dfile= "${dpath}${ofile##*/}" If [-F "$ofile"] && [-S "$ofile"]; Then if [!-D "$dpath"]; Then # Create folder Mkdir-p "$dpath" fi cp "$ofile" "$dfile" # Copy file cat/dev/n
ull > "$ofile" # Create Empty file echo "${ofile} Copy to ${dfile} success" fi} function Clearexpire () { If [-D "$backup _path"]; then echo ${expire:=30} >/dev/null $ (fIND $backup _path-name "*.log"-type f-mtime + $expire-exec rm {} \;) # Delete expire file $ (Find $backup _path-m
indepth 1-depth-empty-type d-exec rm-r {} \;) # Delete empty folder else echo ' ${backup_path} NOT exists ' FI} backup Clearexpire exit 0
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/