Header

  1. View current page

    Plusha's Computer memos

Profile_image?t=1224292764&type=big
0

gpl backup utils

Gpl Backup Manager (gplbackup)

self document

        Gpl Backup Manager : backup files matching extensions recursively

        Usage :

                gplbackup [cfg filename]

        Optional parameters :

                cfg filename    : configuration file(yaml file) name

                --cfg > gplbackup.yml           : generate sample 'gplbackup.yml' file

        Configuration file

                see sample 'gplbackup.yml' file. (use --cfg option)

 

Gpl backup manager는 현재 디렉토리 하위의 디렉토리를 돌아다니며 원하는 확장자의 파일들을 backup해주는 프로그램입니다. 백업할 때에는 (현재 디렉토리에서 상대적인) 디렉토리 구조를 그대로 만들어주며 백업을 합니다. Backup 하고자 하는 디렉토리와 파일 설정은 yml 파일을 이용하여 해줍니다. 예제 yml 파일은

  1. gplbackup --cfg > gplbackup.yml

과 같이 생성할 수 있습니다. 이렇게 생기는 yml 파일은 아래와 같습니다. 파일은 YAML 문법을 따르는데, 간단하기 때문에 YAML 문법을 몰라도 아래 파일을 수정하여 사용할 수 있습니다.

 

  • Sample yml file

# Gpl Backup Manager Configuration File
# Date : 2008.02.21

# Source directories you want to backup
sourceDirectory :
- Documents
- lib

# Extensions of files you want to backup
extensions :
- .f
- .f90
- .c
- .rb
- .sh
- Makefile
- .tex

# A directory name to which the backup files will be copied
targetDirectory : gop642Bak

# Print the copying process (T/F)
verbose : T

# Make "gop642Bak-2008.02.21.tgz" file using the targetDirectory (T/F)
makeTarBall : T

# Remove the targetDirectory after backup (T/F) - when you want tgz file only
removeBackupDir : F

# Files containing these words in their absolute path will be omitted
exclude :
- 'backup'
- 'lib/dms'
- 'lib/UMFPACK'
- 'lib/SU'
- 'lib/seplib'
- '.svn'

 

예제의 yml 파일에서 #으로 시작하는 부분은 comment입니다.

  1. sourceDirectory :

아래에 '-'을 긋고 backup하고자 하는 디렉토리 이름을 적습니다. Backup은 하위 디렉토리까지 recursive하게 합니다. '- .'과 같이 적으면 현재 디렉토리와  하위 디렉토리의 모든 파일들을 대상으로 backup합니다. 이 때 모든 파일들을 다 backup하는 것이 아니라

  1. extensions :

에 해당하는 파일들만 backup합니다. 꼭 확장자가 아니라도

  1. - Makefile

과 같이 파일 이름의 끝부분이 같으면 backup합니다. Backup할 때에는 현재 디렉토리 아래에

  1. targetDirectory :

에 지정된 디렉토리를 만들고, 그 아래 파일이 들어있는 디렉토리를 만들어 backup합니다. targetDirectory 이름은 현재 hostname을 기준으로 만듭니다.

  1. verbose :
  2. makeTarBall :
  3. removeBackupDir :

은 T, F로 표시하고 backup 과정을 화면으로 보여줄지, 디렉토리를 만들어 backup한 후 디렉토리를 tgz 파일로 압축할 것인지, 압축 후 backup 디렉토리를 지울 것인지 지정해줍니다. 압축 파일명은 기본적으로 targetDirectory 이름에 현재 날짜를 더해서 만들어줍니다. 같은 이름의 파일이 존재할 경우 뒤에 숫자를 붙여 새로 만들 파일의 이름을 변경해줍니다.

Backup할 때에는 'extensions :'에 맞더라도 절대경로에 'exclude :'의 내용이 들어가 있는 파일은 제외합니다.

 

Learning by doing

 

실행 예를 볼까요? 현재 디렉토리 아래에 gplbackup.yml 파일과 test1, test2, test3 세 개의 디렉토리가 있고, 각각의 디렉토리에는 다음과 같은 파일들이 있습니다.

  1. $ ls -R
    .:
    gplbackup.yml  test1  test2  test3
    ./test1:
    file1  file2  file2.f90
    ./test2:
    file2.f  file2.f90  file3.f90
    ./test3:
    file1.f90  file2.c

 

gplbackup.yml 파일의 내용은 다음과 같습니다.

  1. $ cat gplbackup.yml
  2. # Gpl Backup Manager Configuration File
  3. # Date : 2008.11.18
  4. # Source directories you want to backup
  5. sourceDirectory :
  6. - .
  7. # Extensions of files you want to backup
  8. extensions :
  9. - .f90
  10. # A directory name to which the backup files will be copied
  11. targetDirectory : node480Bak
  12. # Print the copying process (T/F)
  13. verbose : T
  14. # Make "node480Bak-2008.11.18.tgz" file using the targetDirectory (T/F)
  15. makeTarBall : T
  16. # Remove the targetDirectory after backup (T/F) - when you want tgz file only
  17. removeBackupDir : F
  18. # Files containing these words in their absolute path will be omitted
  19. exclude :
  20. - 'test3'

 

현재 디렉토리 아래의 모든 디렉토리를 돌며 backup하는데 .f90 파일만 backup하고, 경로에 'test3'이라는 문자열이 들어간 파일은 제외합니다. 실행 결과는 다음과 같습니다.

 

  1. $ gplbackup gplbackup.yml
  2. in .
  3. cp  ./test2/file2.f90     node480Bak/./test2
  4. cp  ./test2/file3.f90     node480Bak/./test2
  5. cp  ./test1/file2.f90     node480Bak/./test1
  6. 3 files are backed up
  7.  
  8. making tgz ball : node480Bak/
  9. node480Bak/test2/
  10. node480Bak/test2/file2.f90
  11. node480Bak/test2/file3.f90
  12. node480Bak/test1/
  13. node480Bak/test1/file2.f90
  14.  
  15. node480Bak-20081118.tgz : 207 bytes

 

현재 디렉토리 밑에 'node480Bak' 라는 디렉토리를 만들고(hostname이 'node480'입니다) 그 아래에 디렉토리 구조를 유지하며 .f90 파일들을 backup합니다. yml 파일에서 verbose: T 라고 했기 때문에 backup 과정을 화면으로 출력해주고, makeTarBall: T 라고 했기 때문에 backup 디렉토리를 압축하여 node480Bak-20081118.tgz 파일을 만들어줍니다. 또한, 압축 파일의 크기도 보여줍니다.

 

이 프로그램은 ruby 프로그래밍 언어로 만들었기 때문에 실행하기 위해서는 ruby(version 1.8 이상)가 필요합니다. 개인적으로 상당히 유용하게 쓰고 있는데, 필요하신 분은 여기에서 받아 쓰세요~^^

History

Last edited on 11/18/2008 16:07 by plusha

Comments (0)

You must log in to leave a comment. Please sign in.