리포지토리 백업과 복원
이 섹션은 다양한 사용 사례에 맞춰 lakeFS 리포지토리를 백업하고 복원하는 방법을 설명해요:
출처: 문서
본문
-
재해 복구(Disaster Recovery): 재해 발생 시 복원할 수 있도록 리포지토리를 정기적으로 백업하고 싶은 경우. 리포지토리의 스토리지 네임스페이스도 가능하면 지리적으로 분리된 다른 위치에 백업해 두어야 해요.
-
리포지토리 마이그레이션: 한 환경의 리포지토리를 다른 lakeFS 환경으로 옮기고 싶은 경우.
-
리포지토리 복제(Clone): 리포지토리를 복제하고 싶은 경우.
Tip
lakeFS 리포지토리를 백업, 마이그레이션 또는 복제하는 방법은 Python 샘플 노트북을 참고하세요.
커밋하기
백업 프로세스는 커밋되지 않은 데이터를 백업하지 않으므로, 백업을 실행하기 전에 스테이징된 모든 쓰기를 커밋하세요. 다만 이 과정은 선택 사항이에요.
lakeFS UI에서 수동으로 커밋할 수도 있고, 프로그래밍 방식으로 커밋되지 않은 변경을 처리할 수도 있어요. 아래 Python 예제는 lakeFS의 모든 브랜치를 순회하며 커밋되지 않은 데이터를 커밋하는 방법을 보여주지만, 리포에 브랜치가 많으면 시간이 상당히 걸릴 수 있어요:
import lakefs
repo = lakefs.Repository("example-repo")
for branch in repo.branches():
for diff in repo.branch(branch.id).uncommitted():
repo.branch(branch.id).commit(message='Committed changes to backup the repository')
리포지토리 백업
메타데이터 덤프
lakeFS API나 CLI로 리포지토리의 메타데이터/refs를 덤프하세요.
- lakeFS Python SDK로 메타데이터를 덤프하는 코드 예시 (이 과정은 리포지토리의 스토리지 네임스페이스에
_lakefs/refs_manifest.json파일을 생성해요):
lakefs_sdk_client.internal_api.dump_refs("example-repo")
- lakeFS CLI로 메타데이터를 덤프하고 리포지토리의 S3 스토리지에 업로드하는 명령 예시:
lakectl refs-dump lakefs://example-repo > refs_manifest.json
aws s3 cp refs_manifest.json s3://source-bucket-name/example-repo/_lakefs/refs_manifest.json
- lakeFS CLI로 메타데이터를 덤프하고 리포지토리의 Azure Blob 스토리지에 업로드하는 명령 예시:
lakectl refs-dump lakefs://example-repo > refs_manifest.json
az storage blob upload --file refs_manifest.json --container-name sourceContainer --name example-repo/_lakefs/refs_manifest.json --account-name source-storage-account-name --account-key <source-storage-account-key>
Warning
메타데이터를 덤프한 직후에 lakeFS 서비스를 종료해야 다른 누구도 소스 리포지토리를 변경하지 못하게 할 수 있어요.
백업 스토리지 위치로 데이터 복사
리포지토리의 스토리지 네임스페이스를 다른, 가능하면 지리적으로 분리된 위치로 복사하세요. 복사 명령은 객체 스토리지 종류와 사용하는 도구에 따라 달라져요.
- S3 명령 예시:
aws s3 sync s3://source-bucket-name/example-repo s3://target-bucket-name/example-repo
- Azure azcopy 명령 예시:
azcopy copy 'https://source-storage-account-name.blob.core.windows.net/sourceContainer/example-repo/*?source_container_SAS_token' 'https://target-storage-account-name.blob.core.windows.net/targetContainer/example-repo?target_container_SAS_token' --recursive
Info
백업 스토리지 위치로 데이터 복사를 마치면 lakeFS 서비스를 다시 시작할 수 있어요.
리포지토리 복원
새로운 베어(Bare) 리포지토리 만들기
리포지토리를 복제하려면 새 이름으로 베어 lakeFS 리포지토리를 만들고, 마이그레이션이나 복원이 목적이라면 동일한 리포지토리 이름을 사용하세요.
- S3 스토리지로 베어 lakeFS 리포지토리를 만드는 Python 예시:
lakefs.Repository("target-example-repo").create(bare=True, storage_namespace="s3://target-bucket-name/example-repo", default_branch="same-default-branch-as-in-source-repo")
- Azure 스토리지로 베어 lakeFS 리포지토리를 만드는 Python 예시:
lakefs.Repository("target-example-repo").create(bare=True, storage_namespace="https://target-storage-account-name.blob.core.windows.net/targetContainer/example-repo", default_branch="same-default-branch-as-in-source-repo")
- S3 스토리지로 베어 lakeFS 리포지토리를 만드는 lakeFS CLI 명령:
lakectl repo create-bare lakefs://target-example-repo s3://target-bucket-name/example-repo --default-branch "same-default-branch-as-in-source-repo"
- Azure 스토리지로 베어 lakeFS 리포지토리를 만드는 lakeFS CLI 명령:
lakectl repo create-bare lakefs://target-example-repo https://target-storage-account-name.blob.core.windows.net/targetContainer/example-repo --default-branch "same-default-branch-as-in-source-repo"
새 리포지토리로 메타데이터 복원
restore_refs를 실행해 모든 커밋, 태그, 브랜치를 불러오세요.
- 새 리포지토리로 메타데이터를 복원하는 Python 예시. 먼저 메타데이터 덤프 과정에서 만든 refs_manifest.json 파일을 다운로드하세요:
aws s3 cp s3://target-bucket-name/example-repo/_lakefs/refs_manifest.json .
azcopy copy 'https://target-storage-account-name.blob.core.windows.net/targetContainer/example-repo/_lakefs/refs_manifest.json?<target_container_SAS_token>' .
그다음 refs_manifest.json 파일을 읽고 새 리포지토리로 메타데이터를 복원하세요:
with open('./refs_manifest.json') as file:
refs_manifest_json = json.load(file)
print(refs_manifest_json)
target_lakefs_sdk_client.internal_api.restore_refs(target_repo_name, refs_manifest_json)
- S3 스토리지로 새 리포지토리에 메타데이터를 복원하는 lakeFS CLI 명령:
aws s3 cp s3://target-bucket-name/example-repo/_lakefs/refs_manifest.json - | lakectl refs-restore lakefs://target-example-repo --manifest -
- Azure 스토리지로 새 리포지토리에 메타데이터를 복원하는 lakeFS CLI 명령:
az storage blob download --container-name targetContainer --name example-repo/_lakefs/refs_manifest.json --account-name target-storage-account-name --account-key <target-storage-account-key> | lakectl refs-restore lakefs://target-example-repo --manifest -
Tip
백업을 정기적으로 수행한다면, 재해 시 실제로 리포지토리를 복원할 수 있는지 확인하도록 복원 프로세스를 주기적으로 테스트하는 것이 강력히 권장돼요.
백업·복원용 Python 헬퍼 스크립트
더 매끄러운 리포지토리 백업/복원 작업을 위해 lakeFS 리포지토리에서 제공하는 lakefs-refs.py 스크립트를 사용할 수 있어요.
개요
lakefs-refs.py 스크립트는 이 문서에서 설명한 백업·복원 절차를 자동화해요. 리포지토리 레퍼런스를 덤프하고 복원하는 데 필요한 모든 단계를 처리해 주므로, 리포지토리 마이그레이션과 백업 작업을 더 간단하고 실수 없이 진행할 수 있어요.
사전 준비
필요한 의존성을 설치하세요:
pip install -r requirements.txt
사용 예시
리포지토리 레퍼런스 덤프
스크립트로 리포지토리 메타데이터를 손쉽게 덤프할 수 있어요:
python lakefs-refs.py dump <repository-name> [--all] [--commit] [--rm] [--endpoint-url <url>] [--access-key-id <key>] [--secret-access-key <secret>]
옵션:
-
<repository-name>: 덤프할 특정 리포지토리의 이름 -
--all: 특정 리포지토리 대신 모든 리포지토리를 덤프 -
--commit: 덤프 전에 커밋되지 않은 변경을 커밋 -
--rm: 덤프 성공 후 리포지토리 정의 삭제 -
인증 옵션 (아래 참고)
리포지토리 레퍼런스 복원
매니페스트 파일에서 리포지토리 메타데이터를 복원할 때 사용해요:
python lakefs-refs.py restore <manifest-file> [<manifest-file2> ...] [--ignore-storage-id] [--endpoint-url <url>] [--access-key-id <key>] [--secret-access-key <secret>]
옵션:
-
<manifest-file>: 복원할 매니페스트 파일 하나 이상 -
--ignore-storage-id: storage_id 없이 리포지토리 생성 (다른 스토리지 백엔드로 마이그레이션할 때 유용) -
인증 옵션 (아래 참고)
인증
스크립트는 lakectl과 동일한 인증 방식을 사용해요. 명령줄 파라미터, 환경 변수(LAKECTL_*), ~/.lakectl.yaml 설정 파일을 통한 인증을 지원해요.
더 알아보기 (Learn more)
공식 문서의 백업/복원 페이지는 https://docs.lakefs.io/admin/backup-and-restore 에서 확인할 수 있어요.