주기적 폴더 복제
폴더 복제
중요한 사진 백업
0 2 * * * /home/hyunsu/BackUpCenter/backUpPicture.sh /data/ext/WD4TB/Pictures4T /data/ext/2TB/backup > /home/hyunsu/BackUpCenter/backupPictures.log
"/data/ext/WD4TB/Pictures4T" 폴더의 모든 파일을 "/data/ext/2TB/backup/Pictures4T"에 일단위로 복제함
#!/bin/sh
export _SDATE=$(date +"%Y-%m-%d %H")
OrgDirectory=$1
BackUpDirectory=$2
DirectoryFound=$(find $OrgDirectory -type d )
countfiles=0
MakeList()
{
echo "Make List !"
find $OrgDirectory -type f > $BackUpDirectory/pictureList.list
}
checkFileExist()
{
Orgfilename="$1"
filename=`echo "$1" | cut -d'/' -f5-`
#echo ">> " $BackUpDirectory/$filename
if [ -f "$BackUpDirectory/$filename" ]; then
printf "."
else
echo -e "\nNOT EXIST --> Copy " $Orgfilename " --> " $BackUpDirectory "/" $filename
cp "$Orgfilename" "$BackUpDirectory/$filename"
fi
}
checkDirectoryExist()
{
dirname=`dirname "$1"`
if [ -d "$BackUpDirectory/$dirname" ]; then
printf "-"
else
echo -e "\nNOT EXIST --> Makedirectory " $BackUpDirectory/$dirname
mkdir -p "$BackUpDirectory/$dirname"
fi
}
#echo -e "\n\n##########################################"
echo "START "$_SDATE
if [ $# -ne 2 ];then
echo "ERROR 1.target folder, 2. backup folder!"
echo " ex : /home/hyunsu/BackUpCenter/backUpPicture.sh /data/ext/WD4TB/Pictures /data/ext/2TB/backup/Pictures"
exit 1
fi
# 목록 파일을 만든다 .
MakeList
LINE_NO=$(cat $BackUpDirectory/pictureList.list | wc -l) # 몇 줄 라인인지 읽음
echo Total source file count : $LINE_NO line
while read line
do
dirname=`echo $line | cut -d'/' -f5-`
checkDirectoryExist "${dirname}"
checkFileExist "${line}"
countfiles=$(($countfiles+1))
done < $BackUpDirectory/pictureList.list
echo -e "\n Total check file count : " $countfiles " line"
_SDATE=$(date +"%Y-%m-%d %H")
echo -e "\nFINISH "$_SDATE
echo "##########################################"
exit 0