Aug 14

网上的都要用到 find -mtime,这个参数默认的 busybox 是不支持的,当然你可以下 findunti ,我这个脚本无需额外的程序支持:

#!/bin/sh
# optware backup
# Sun Feb 19 00:34:42 CST 2012
# by Punk

keep=3                                                #保留历史备份数
backup_source="opt"                            #需要备份的目录,不可有/开头
backup_dest="/cifs2/hdtv/!opt_bak/"      #备份文件存储目录
date=`date +%Y-%m-%d`
hostname=$(hostname -s)
prename="$hostname-optware"
filename="$prename-$date.tgz"

delete_old() {
echo Deleting old backup of Optware...
totalline=`find "$backup_dest" -name "$prename*.tgz" | wc -l`
if [ $totalline -ge $keep ];then
    dell=$(($totalline-$keep))
    find "$backup_dest" -name "$prename-*.tgz" | sort | head -n $dell | xargs rm -rf
fi
echo Deleting old backup of Optware Finished!
}

backup() {
echo "Backing Up Your Optware System..."
tar czf $backup_dest/$filename -C / $backup_source
echo "Optware Backup Finished!"
}
backup
delete_old
点击显示引用框
引用本文,复制粘贴...