Contents

조회 수 10596 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
#!/usr/bin/perl

#################################################################################################
##                                                                                             ##
##  제  작 : 후리자 (2003년 4월 3일) maritpe@hotmail.com                                       ##
##  파일명 : fullbackup.pl                                                                     ##
##                                                                                             ##
##  풀백업을 쉽게 하게 해준다                                                                  ##
##                                                                                             ##
#################################################################################################

  $computer = "cmd"; # 백업파일 앞에 붙는 글자
  $tgzpath = "/backup/"; # 백업한 파일을 저장할 경로 (뒤에 슬래쉬 꼭!)

  $tarfile = "/bin/tar"; # tar 파일의 경로
  $rmfile = "/bin/rm"; # rm 파일의 경로

  # 백업할 디렉토리 목록
  @backupdir = (
                [ "/home/users/js/",          "" ],
                [ "/home/users/simi/",        "" ],
                [ "/home/users/stormbr/",     "" ],
                [ "/home/users/tohlead/",     "" ],
                [ "/home/users/greesp/",      "" ],
                [ "/home/staff/hooriza/",     "--exclude=/home/staff/hooriza/storage" ],
                [ "/home/staff/lodoss/",      "" ],
                [ "/home/staff/dawnsea2/",    "" ],
                [ "/htdocs/",                 "" ],
                [ "/cmd/club/",               "--exclude=/cmd/club/storage" ]
               );

#################################################################################################

# 명령어 실행하기
sub execCommand($)
{
  my($command) = @_;

  print "명령실행 : $command\n";
  $result = `$command`;
  
  if ($result)
  {
    print "실행결과 : $result\n";
  }
}

# 파일내용 읽기
sub getFileData($)
{
  my($filename) = @_;
  $retval = `cat $filename`;
  $retval =~ s/\n//gi;
  
  return $retval;
}

# 파일내용 쓰기
sub setFileData($$)
{
  my($filename, $data) = @_;
  `echo $data > $filename`;
}

# 현재 날짜 얻기
sub getCurrentDate()
{
  $retval = `date +%Y%m%d`;
  $retval =~ s/\n//gi;

  return $retval;
}

if ($#ARGV != 0)
{
  die "오류 : 인자로 full 또는 incr 가 들어가야합니다.\n";
}

$backuptype = shift(@ARGV);

if ($backuptype ne "full" && $backuptype ne "incr")
{
  die "오류 : 인자로 full 또는 incr 가 들어가야합니다.\n";
}

$lastFBdatefile = $tgzpath.$computer."_fullbackup_lastdate"; # 마지막으로 full 백업이 된 날짜 파일
$lastIBdatefile = $tgzpath.$computer."_incrbackup_lastdate"; # 마지막으로 incr 백업이 된 날짜 파일

$today = getCurrentDate();
$lastFBdate = getFileData($lastFBdatefile); # 마지막으로 full 백업 된 날짜 얻기
$lastIBdate = getFileData($lastIBdatefile); # 마지막으로 incr 백업 된 날짜 얻기

# fullbackup 디렉토리 만들기
execCommand("mkdir ".$tgzpath."fullbackup");

# incrbackup 디렉토리 만들기
execCommand("mkdir ".$tgzpath."incrbackup");

foreach my $arrayret(@backupdir)  
{
  # 배열 값 받아오기
  $destdir = @$arrayret[0];
  $option = @$arrayret[1];
  
  # 슬래쉬를 언더바로 바꾼 대상경로
  $udestdir = $destdir;
  $udestdir =~ s/\//_/gi;

  # 기존의 백업파일 삭제하기
  if ($backuptype eq "full")
  {
    if ($lastFBdate ne "")
    {
      print "기존의 압축파일을 삭제합니다\n";
      
      # 지울압축파일의 경로 설정
      $deltgzfile = $tgzpath."fullbackup/".$computer.$lastFBdate.$udestdir.".tgz";
      
      # 삭제하기
      execCommand("$rmfile -f $deltgzfile");
    }

    print "새로운 압축파일을 만듭니다\n";
  
    # 압축파일의 경로 설정
    $tgzfile = $tgzpath."fullbackup/".$computer.$today.$udestdir.".tgz";
  
    # 압축하기
    execCommand("$tarfile -czvf $tgzfile $destdir $option");
  }
  else
  {
    if ($lastFBdate > $lastIBdate) # full 백업한 이후로 incr 백업을 한번도 안 했으면
    {
      print "기존의 압축파일을 삭제합니다\n";
      
      # 지울압축파일의 경로 설정
      $deltgzfile = $tgzpath."incrbackup/".$computer."????????".$udestdir.".tgz";
      
      # 삭제하기
      execCommand("$rmfile -f $deltgzfile");
    }

    print "새로운 압축파일을 만듭니다\n";
  
    # 압축파일의 경로 설정
    $tgzfile = $tgzpath."incrbackup/".$computer.$today.$udestdir.".tgz";
  
    # 압축하기
    execCommand("$tarfile --newer '$lastIBdate' -zcf $tgzfile $destdir $option");
  }
}

if ($backuptype eq "full")
{
  # 마지막으로 full 백업 된 날짜 수정
  setFileData($lastFBdatefile, $today);
}
else
{
  # 마지막으로 incr 백업 된 날짜 수정
  setFileData($lastIBdatefile, $today);
}


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
1173 Develop [ios] 아이폰용 앱 오픈 소스들 hooni 2013.04.23 466226
1172 Develop [ios] 언어, 지역, 국가 설정 가져오기 hooni 2014.05.12 269345
1171 Develop 자주 쓰는 Docker 명령어 alias hooni 2020.01.10 268703
1170 Etc 베지어 곡선 (Bezier curve) file hooni 2013.08.18 220311
1169 Develop [ios] Start developing your navigation app for CarPlay without enrollment file hooni 2020.02.22 124610
1168 Develop [android] 만화 어플 소스코드 file hooni 2013.04.23 92832
1167 Develop 레고 마인드스톰 NXT 수도쿠, 큐브 소스코드.. 20 file hooni 2013.04.23 81374
1166 Algorithm 디피헬만(Diffie-Hellman) 초간단 개념.. hooni 2013.04.23 81016
1165 Develop [c#] Hashtable <-> Json (dll 포함) file hooni 2013.04.23 80648
1164 Develop [C#] MD5, SHA1 해시 & 인코딩 hooni 2013.04.23 77850
1163 Develop [android] 점심 해결 앱 소스 코드 ㅋㅋ file hooni 2013.04.23 76392
1162 PPT [android] XML파서(XMLParser)의 종류와 성능 비교에 대한 발표 자료 file hooni 2013.04.23 75632
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 98 Next
/ 98