study/computer common 2012. 4. 5. 00:29

robocopy

robocopy 

폴더 복사, 이동, 폴더 동기화, 예약된 시간에 작업 시작, 일정 시간 마다 복사하기 등등

매우 다양한 기능을 가진 util입니다.

특히 폴더 내용들을 한쪽에서 다른 쪽으로 동기화 하는 기능이 아주 마음에 들고

커맨드 라인용 프로그램이라 스케줄러에 예약해 놓고 쓰기도 좋습니다.

copy 중단..다시시작시 이어 받기 가능.

소스 확인하여 동기화 가능.

 

여기에 hstart라는 프로그램을 쓰면 백그라운드에서 작동시킬수 있다

 

나는 네트워크 드라이브에 걸었다 ㅋㅋ

 

다운은

http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en

Windows Vista에서는 기본으로 포함이 되는걸로 알고 있습니다.

  

예제

 

1. 폴더 동기화

c:>robocopy c:\foo e:\foo /MIR

  

2. 폴더 동기화: 특정 시간에 시작하기 ( 12시 30분에서 40분 사이에 시작하기 )

c:>robocopy c:\foo e:\foo /MIR /RH:1230-1240

  

3. 폴더 동기화: 1분 간격으로 모니터하여 최소 5개 파일이 변경이 되면 동기화하기

c:>robocopy c:\foo e:\foo /MIR /MOT:5 /MON:1

  

4. 폴더 동기화: 1분 간격으로 최소 5개 파일이 변경이 되면 동기화하기 + 로그 남기기

c:>robocopy c:\foo e:\foo /MIR /MOT:1 /MON:5 /LOG:copy.log

 

현재 서비스중인 데이터를 다른 서버로 이전하고 그 서버에서 데이터를 서비스하려고 합니다.

복사하는 중에 이용자들이 새로운 데이터를 올릴 수도 있고..

장애시간을 최소화시키려면 최소한 데이터 복사를 두 번은 해야 합니다.

서비스 장비를 옮기기 전에 새 장비로 데이터 복사를 일단 한 번 하고,

서비스 장비를 바꾼 후에 다시 한 번 복사를 해주어야 합니다.

데이터 복사 중에 이용자들은 기존 서버에 새로운 데이터를 올렸을 테니까요.

탐색기나 일반 copy 명령을 사용하면 모든 데이터를 다시 복사하게 됩니다.

이런 시간 낭비를 해서는 안되겠지요?

불필요한 파일 복사를 하는 동안 신규 장비에는 필요한 파일이 없어서 이용자들이 불만을 토로할 겁니다.

이러한 경우에 요긴하게 쓸 수 있는 것이 robocopy.exe 라는 유틸리티입니다.

이 유틸은 기본적으로 폴더 단위의 복사를 합니다.

모든 파일을 복사하는 것은 당연히 기본 기능이고,

옵션을 주게 되면 source와 destination의 파일 존재 여부와 file datetime을 비교하여 새로운 파일만 복사하도록 할 수 있습니다.

이 방법을 쓰면 데이터 이동 시간을 현저히 낮출 수 있습니다.

예를 들어

robocopy c:data h:data /S /XO

이렇게 명령을 주면 c:data 폴더와 그 하위 폴더를 h:data 폴더에 하위 폴더까지 동일하게 복사를 합니다.

위와 같이 /X0 옵션을 사용하면 file datetime을 비교하여 갱신된 파일만, 그리고 신규 파일만 복사를 합니다.

robocopy는 또한 파일 복사 실패시 기본적으로 100만번의 retry를 합니다.

네트워크를 통한 복사를 할 때 네트워크가 잠시 상태가 안좋아도 100만번 retry 동안에 복구가 되면

복사는 이어서 진행이 되는 것이죠.

----------------------------------------------------------------------

ROBOCOPY v 1.96 : Robust File Copy for Windows NT

----------------------------------------------------------------------

Started : Thu Nov 10 13:58:32 2005

Usage : ROBOCOPY source destination [file [file]...] [options]

source : Source Directory (drive:path or serversharepath).

destination : Destination Dir (drive:path or serversharepath).

file : File(s) to copy (names/wildcards: default is "*.*").

Copy options: /S : copy Subdirectories, but not empty ones.

/E : copy subdirectories, including Empty ones.

/LEV:n : only copy the top n LEVels of the source directory tree.

/Z : copy files in restartable mode.

/SEC : copy SECurity info (both source and dest must be NTFS).

/SECFIX : FIX SECurity info on existing files and dirs.

/TIMFIX : FIX TIMestamps on existing destination files.

/MOV : MOVe files (delete from source after copying).

/MOVE : MOVE files AND dirs (delete from source after copying).

/PURGE : delete dest files/dirs that no longer exist in source.

/MIR : MIRror a directory tree (equivalent to /E plus /PURGE).

/A+:[R][A][S][H] : add the given Attributes to copied files.

/A-:[R][A][S][H] : remove the given Attributes from copied files.

/CREATE : CREATE directory tree structure + zero-length files only.

/FAT : create destination files using 8.3 FAT file names only.

File Selection: /A : copy only files with the Archive attribute set

/M : like /A, but remove Archive attribute from source files.

/IA:[R][A][S][H] : Include only files with some of the given Attributes set.

/XA:[R][A][S][H] : eXclude files with any of the given Attributes set.

/XF file [file]... : eXclude Files matching given names/paths/wildcards.

/XD dirs [dirs]... : eXclude Directories matching given names/paths.

/XC | /XN | /XO : eXclude Changed | Newer | Older files.

/XX | /XL : eXclude eXtra | Lonely files and dirs.

Tistory 태그: ,

/IS : Include Same files.

/MAX:n : MAXimum file size - exclude files bigger than n bytes.

/MIN:n : MINimum file size - exclude files smaller than n bytes.

/MAXAGE:n : MAXimum file AGE - exclude files older than n days/date.

/MINAGE:n : MINimum file AGE - exclude files newer than n days/date.

(If n < 1900 then n = n days, else n = YYYYMMDD date).

Retry Options: /R:n : number of Retries on failed copies: default is 1 million.

/W:n : Wait time between retries: default is 30 seconds.

/REG : Save /R:n and /W:n in the Registry as default settings.

/TBD : wait for sharenames To Be Defined (retry error 67).

Logging Options: /L : List only - don't copy, timestamp or delete any files.

/X : report all eXtra files, not just those selected.

/V : produce Verbose output, showing skipped files.

/NP : No Progress - don't display % copied.

/ETA : show Estimated Time of Arrival of copied files.

/LOG:file : output status to LOG file (overwrite existing log).

/LOG+:file : output status to LOG file (append to existing log).

[사용법]

robocopy [원본 대상 폴더나 디렉터리] [복사 대상 폴더나 디렉터리] /MIR /R:2 /W:5 /NP /LOG+:[로그파일 생성 경로]

'study > computer common' 카테고리의 다른 글

Windows Script Host(WSH) 기초  (0) 2012.04.06
윈도우 FTP 명령어  (0) 2012.04.06
7z 스크립트 & 백업 스크립트  (0) 2012.04.06
파일/폴더 공유  (0) 2012.04.05