Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- source=$1
- backup=$2
- mk_dir() {
- # 각각의 폴더 생성을 위해 금년도, 이번달, 오늘 날짜를 각각 변수로 지정합니다.
- Y=`date +%Y`
- m=`date +%m`
- d=`date +%d`
- foldYmd=`ls -d $backup/$Y/$m/$d`
- if [ "$foldYmd" != "$backup/$Y/$m/$d" ]; then
- mkdir -p ~$backup/$Y
- mkdir -p ~$backup/$Y/$m
- mkdir -p $backup/$Y/$m/$d
- fi
- now=`date +%H%M`
- mkdir -p $backup/$Y/$m/$d/$now
- }
- backup() {
- echo "source :$source backup : $backup"
- date_file=`ls $backup/date`
- if [ "$date_file" = "$backup/date" ]; then
- # 1년 넘은 쪽지들은 삭제
- find $backup -type d -mtime +365 -exec rm -r {} \;
- list=`find $source -type f -newer $backup/date`
- count=`echo $list | wc -c`
- if [ "$count" != 1 ]; then
- mk_dir
- IFS="
- "
- for l in $list ; do
- cp -av $l $backup/$Y/$m/$d/$now
- done
- IFS=""
- fi
- date > $backup/date
- else
- mk_dir
- find $backup -type f -exec cp -av {} $backup/$Y/$m/$d/$now \;
- date > $backup/date
- fi
- }
- check_source=`ls -d $source`
- if [ "$check_source" = "$source" ]; then
- check_backup=`ls -d $backup`
- if [ "$check_backup" = "$backup" ]; then
- backup
- else
- echo "there is no $backup"
- fi
- else
- echo "there is no $source"
- fi
- exit
Advertisement
Add Comment
Please, Sign In to add comment