Guest User

Untitled

a guest
Dec 4th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.24 KB | None | 0 0
  1. #!/bin/sh
  2. source=$1
  3. backup=$2
  4.  
  5. mk_dir() {
  6.     # 각각의 폴더 생성을 위해 금년도, 이번달, 오늘 날짜를 각각 변수로 지정합니다.
  7.     Y=`date +%Y`
  8.     m=`date +%m`
  9.     d=`date +%d`
  10.    
  11.     foldYmd=`ls -d $backup/$Y/$m/$d`
  12.     if [ "$foldYmd" != "$backup/$Y/$m/$d" ]; then
  13.         mkdir -p ~$backup/$Y
  14.         mkdir -p ~$backup/$Y/$m
  15.         mkdir -p $backup/$Y/$m/$d
  16.     fi
  17.    
  18.     now=`date +%H%M`
  19.     mkdir -p $backup/$Y/$m/$d/$now
  20. }
  21.    
  22. backup() {
  23.     echo "source :$source backup : $backup"
  24.     date_file=`ls $backup/date`
  25.     if [ "$date_file" = "$backup/date" ]; then
  26.         # 1년 넘은 쪽지들은 삭제
  27.         find $backup -type d -mtime +365 -exec rm -r {} \;
  28.         list=`find $source -type f -newer $backup/date`
  29.         count=`echo $list | wc -c`
  30.         if [ "$count" != 1 ]; then
  31.             mk_dir
  32.             IFS="
  33.             "
  34.             for l in $list ; do
  35.             cp -av $l $backup/$Y/$m/$d/$now
  36.             done
  37.                 IFS=""
  38.         fi
  39.         date > $backup/date
  40.     else
  41.         mk_dir
  42.         find $backup -type f -exec cp -av {} $backup/$Y/$m/$d/$now \;
  43.         date > $backup/date
  44.     fi
  45. }
  46.  
  47. check_source=`ls -d $source`
  48. if [ "$check_source" = "$source" ]; then
  49.     check_backup=`ls -d $backup`
  50.     if [ "$check_backup" = "$backup" ]; then
  51.         backup
  52.     else
  53.         echo "there is no $backup" 
  54.     fi
  55. else
  56.     echo "there is no $source"
  57. fi
  58. exit
Advertisement
Add Comment
Please, Sign In to add comment