以网页下的文件为例
/var/www/html/ 网页目录
echo 1111 > /var/www/html/a.html
echo 2222 > /var/www/html/b.html
vim /shell/web.sh
#!/bin/bash
webdir=/webbakdir
if [ ! -e $webdir ];then
mkdir $webdir
fi
cd /var/www/html
for file in `ls *.html`
do
if [ ! -e $webdir/$file ];then
cp $file $webdir
fi
done
执行脚本并查看
[[email protected] webbackdir]sh web.sh
[[email protected] webbackdir]# ls /webbackdir
a.html b.html
为了节省空间可以将备份压缩
#!/bin/bash
webdir=/webbakdir
day=`date +%F`
if [ ! -e $webdir ];then
mkdir $webdir
fi
cd /var/www/html
for file in `ls *.html`
do
if [ ! -e $webdir/$file ];then
tar -zcf $webdir/web-${day}.tar.gz $file &> /dev/null
fi
done
时间: 2024-10-25 23:45:43