Skip to main content

Backup 폴더 공유

Backup 폴더 공유

OrgDirectory=/home/hyunsu/Pictures/ 여기서 BackUpDirectory=/data/ext/WD4TB/backup/Pictures로 파일 공동화 .. 근데 삭제가 없네 

#!/bin/sh

export SDATE=$(date +"%Y%m%d%H")
OrgDirectory=/home/hyunsu/Pictures/
BackUpDirectory=/data/ext/WD4TB/backup/Pictures
FilesFound=$(find $OrgDirectory )

checkFileExist()
{
	filename=`echo $1 | cut -d'/' -f5-`
	echo ">> " $BackUpDirectory/$filename
	if [ -f $BackUpDirectory/$filename ]; then
		echo "EXIST"
		echo 
	else
		echo "NOT EXIST --> Copy " $1 " --> " $BackUpDirectory/$filename
		cp $1 $BackUpDirectory/$filename
	fi
}

checkDirectoryExist()
{
	filename=`echo $1 | cut -d'/' -f5-`
	echo ">> " $BackUpDirectory/$filename
	if [ -d $BackUpDirectory/$filename ]; then
		echo "EXIST"
		echo
	else
		echo "NOT EXIST --> Makedirectory " $BackUpDirectory/$filename
		mkdir $BackUpDirectory/$filename
	fi
}

echo "START "$_SDATE
for file in $FilesFound
do
    echo "--  ${file}"
	if [ -f "${file}" ]; then
		echo "${file} file."
		checkFileExist ${file}
	fi
	if [ -d "${file}" ]; then
		echo "${file} directory."
		checkDirectoryExist ${file}
	fi
done