✍ Confluence 첨부파일을 API 호출로 삭제하는 방법을 공유 합니다. 영문버전 바로가기
https://github.com/pycontribs/confluence 을 활용하였습니다.
curl
호출로 첨부파일을 삭제할 수 있습니다. (휴지통)
서버에서 물리적으로 완전히 삭제하려면,Purge All
까지 해줘야 합니다. (휴지통 비우기)
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)
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))
공간 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
로 첨부파일 체크 한 번 하고 가시죠~