码迷,mamicode.com
首页 > 其他好文 > 详细

只备份某个目录下新产生的文件

时间:2017-03-31 22:35:32      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:新产生目录备份

以网页下的文件为例

/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

执行脚本并查看

[root@master5 webbackdir]sh web.sh

[root@master5 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




本文出自 “12619984” 博客,请务必保留此出处http://12629984.blog.51cto.com/12619984/1912078

只备份某个目录下新产生的文件

标签:新产生目录备份

原文地址:http://12629984.blog.51cto.com/12619984/1912078

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!