目录结构备份和目录备份

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/bin/bash
#
function backupDir {
    bakDir=$1
    tmpDir=$2
    cd $tmpDir && find -L $bakDir -type d -exec mkdir -p $tmpDir{} \;
}
#
function backupFile {
        bakFile=$1
        tmpDir=$2
        backupDir $1 $2
        cd $bakFile && file=`find -L * -type f -exec echo {} \; | grep -v "nohup.out" | grep -v ".*\.log" | grep -v ".*\.lock"`
        for dat in $file
        do
                cp -a $bakFile$dat $tmpDir$bakFile$dat
        done
}
#
dirBak=/home/roo
fileBak1=/home/roo/project1
fileBak2=/home/roo/project2
#
bakName=roo_`date +%Y%m%d`.tar.gz
tmpDir=/home/roo/.tmpdir
#
mkdir -p $tmpDir
#
backupDir $dirBak $tmpDir
backupFile $fileBak1 $tmpDir
backupFile $fileBak2 $tmpDir
#
cd $tmpDir && tar czvf ~/$bakName *
rm -r $tmpDir
#