Confluence 첨부파일 점검하고 삭제하기

·2020년 1월 20일
0

Atlassian

목록 보기
1/1
post-thumbnail

Confluence 첨부파일을 API 호출로 삭제하는 방법을 공유 합니다. 영문버전 바로가기
https://github.com/pycontribs/confluence 을 활용하였습니다.

테스트 환경

  • Confluence 6.1.1
  • Python 2.7.14

방법

curl 호출로 첨부파일을 삭제할 수 있습니다. (휴지통)
서버에서 물리적으로 완전히 삭제하려면, Purge All 까지 해줘야 합니다. (휴지통 비우기)

1) curl 호출로 첨부파일을 삭제할 수 있습니다.

✅ 첨부파일의 id가 필요합니다.
첨부파일마다 고유값의 id를 갖습니다.

$ vi delete_attachment.py
# -*- coding: utf-8 -*-
import sys
import os

reload(sys)
sys.setdefaultencoding('utf-8')

attachmentId = '' # 첨부파일 id
delete_cmd = "curl -v -S -u \"<id>:<password>" -X DELETE \"https://<confluence_url>/rest/api/content/" + str(attachmentId) +"\""

os.system(delete_cmd)

2) 첨부파일의 id를 구하는 코드 입니다.

공간 KEY페이지 제목이 필요합니다.

$ vi get_attachment_id.py
# -*- coding: utf-8 -*-
from confluence import Confluence
import sys

reload(sys)
sys.setdefaultencoding('utf-8')

confluence = Confluence(profile='confluence')

page_title = '' # 페이지 제목
space_key = '' # 공간 KEY

attachments = confluence.getAttachments(page_title, space_key)

for attachment in attachments :
    a_title = attachment['title']
    a_url = attachment['url']
    a_creator = attachment['creator']
    a_fileName = attachment['fileName']
    a_id = attachment['id']
    # MB
    a_fileSize = int(attachment['fileSize']) / 1000000
    # attachment id 출력
    print(str(a_id))

3) Confluence 전체의 ✅ 공간 KEY페이지 제목을 구하는 코드 입니다.

$ vi get_confluence_info.py```

```python
# -*- coding: utf-8 -*-
from confluence import Confluence
import sys

reload(sys)
sys.setdefaultencoding('utf-8')

confluence = Confluence(profile='confluence')
allSpace = confluence.getSpaces()

for space in allSpace :

    if space['type'] == 'global':

        spaceKey = space['key']        
        
        pages = confluence.getPages(spaceKey)

        print('-' * 100)
        # 공간 이름과 KEY 출력
        print(str(space['name']) + "\t" + str(spaceKey))

        total_attachment = 0
        total_fileSize = 0        
        for page in pages :
            pageTitle = page['title']
            # 페이지 제목 출력
            print(pageTitle)
            attachments = confluence.getAttachments(pageTitle, spaceKey)
            total_attachment += len(attachments)

            for attachment in attachments :
                attachment_title = attachment['title']                
                # MB size
                file_size = int(attachment['fileSize']) / 1000000
                total_fileSize += file_size
        
        print(str(total_attachment)) + " 개"
        print(str(total_fileSize)) + " MB"

교훈

Confluence 페이지 복사 기능은 기존 페이지의 첨부파일까지 복사해서 신규 페이지를 생성합니다.
페이지 복사 시, 첨부 파일이 복사되는 것이 눈에 보이지 않는 함정이 있습니다. 😱
※ Confluence v7.1 부터는 첨부파일을 스킵하여 복사하는 기능이 추가 되었다고 합니다.
무거운 페이지를 시작으로 복사가 복사를 낳고 있다면 attachments 용량이 어마무시하게 필요합니다.

💡 이 포스팅을 읽고 있다면 get_confluence_info.py 로 첨부파일 체크 한 번 하고 가시죠~

0개의 댓글