System/OS
2013.04.23 13:14
[perl] 영규가 만든 스크립트.. 하하..
Views 10675 Comment 0
#!/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);
}
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
249 | Develop | [php][laravel] 라라벨 프로젝트 생성 및 구조 | hooni | 2017.12.15 | 2551 |
248 | Etc | How to completely Uninstall Coda | hooni | 2017.10.24 | 2503 |
247 | Develop | [펌] 게임 엔진 만든거 공개합니다. | hooni | 2015.02.21 | 2463 |
246 | Develop | [ios] iOS앱의 Xcode 빌드 과정 | hooni | 2015.01.03 | 2390 |
245 | Develop | [c] 셀프 넘버(Self Number) 구하기 1 | hooni | 2016.09.09 | 2381 |
244 | System/OS | 무료로 HTTPS 적용하기 (Lets' Encrypt) | hooni | 2017.02.16 | 2375 |
243 | Develop | XML, JSON, BSON, MSGPACK 장,단점 비교 | hooni | 2017.01.11 | 2369 |
242 | Develop | [java] netty (비동기 이벤트 방식 네트워크 프레임워크) 사용법 #1 (server) 1 | hooni | 2015.01.02 | 2316 |
241 | System/OS | [mac][추천 무료앱] 구름 입력기 - 국내 맥 사용자를 위한 한글 대안 입력기 1 | hooni | 2015.01.04 | 2299 |
240 | Develop | [android] 버전 별 앱 알림 설정으로 이동하는 방법 | hooni | 2016.11.28 | 2280 |
239 | System/OS | 서버 확장을 위한 두 가지 방법 | hooni | 2018.08.29 | 2259 |
238 | Develop | [android] 안드로이드 앱 문서 샘플 - NCComix | hooni | 2017.07.11 | 2213 |