备份shell

    技术2025-07-12  16

    #! /bin/bash # # config # etcConfig=/etc/wwwbackup.conf if [[ ! -f ${etcConfig} ]]; then echo "${etcConfig} not exists" exit 1 fi while read s t do ss=`date +%F%r`.tar.gz backDir=`basename ${s}` if [[ -d ${s} ]]; then cd ${s} && cd .. tar zcvf ${backDir}${ss} ${backDir} > /dev/null && mv ${backDir}${ss} ${t}${backDir}${ss} & fi done < ${etcConfig} 

    刚学shell一个月,当练手用。

     

    过程中遇到的问题:

        tar命令在使用绝对路径的时候要加上-P参数,不然会出现一个remoting "/"这个的错误,而且解压后的路径是整个绝对路径的目录,关于-P参数,请man tar

     

     

    最新回复(0)