Share streamed backup member extraction
This commit is contained in:
1 parent
4664fc1278
commit
41369b9ffd
3 files changed
+15
-15
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import argparse
|
||||
import gzip
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import tarfile
|
||||
@@ -8,6 +9,7 @@ import zlib
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path, PurePosixPath
|
||||
from shutil import copyfileobj
|
||||
|
||||
from .domain_names import canonical_domain
|
||||
from .mail_node import MailboxSpec
|
||||
@@ -259,6 +261,17 @@ def backup_members(archive):
|
||||
check_tar_padding(archive)
|
||||
|
||||
|
||||
def copy_member(archive, member, target):
|
||||
if member.size < 0:
|
||||
raise ValueError("A file in the backup has an invalid size.")
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
with target.open("xb") as output, archive.extractfile(member) as source:
|
||||
os.fchmod(output.fileno(), 0o600)
|
||||
copyfileobj(source, output, length=1024 * 1024)
|
||||
if output.tell() != member.size:
|
||||
raise ValueError("A file in the backup is incomplete.")
|
||||
|
||||
|
||||
def inspect_backup(path):
|
||||
inventory = BackupInventory()
|
||||
with open_backup(path) as archive:
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import os
|
||||
from contextlib import suppress
|
||||
from pathlib import Path
|
||||
from shutil import copyfileobj
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from .directadmin import (
|
||||
DOCUMENT_ROOTS,
|
||||
BackupInventory,
|
||||
backup_members,
|
||||
copy_member,
|
||||
member_path,
|
||||
open_backup,
|
||||
)
|
||||
@@ -105,14 +104,3 @@ def copy_website(backup, domain, source_root, destination, *, on_copy=None):
|
||||
"bytes": total_bytes,
|
||||
"skipped_non_regular_entries": skipped,
|
||||
}
|
||||
|
||||
|
||||
def copy_member(archive, member, target):
|
||||
if member.size < 0:
|
||||
raise ValueError("A website file has an invalid size in the archive.")
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
with target.open("xb") as output, archive.extractfile(member) as source:
|
||||
os.fchmod(output.fileno(), 0o600)
|
||||
copyfileobj(source, output, length=1024 * 1024)
|
||||
if output.tell() != member.size:
|
||||
raise ValueError("A website file in the archive is incomplete.")
|
||||
@@ -8,8 +8,7 @@ from io import BytesIO
|
||||
from pathlib import Path
|
||||
from tempfile import NamedTemporaryFile, TemporaryDirectory
|
||||
|
||||
from .directadmin import backup_members, member_path, open_backup
|
||||
from .directadmin_website import copy_member
|
||||
from .directadmin import backup_members, copy_member, member_path, open_backup
|
||||
from .node_files import check_root_file, require_root_directory
|
||||
from .web_node_apply import (
|
||||
SitePaths,
|
||||
|
||||
Reference in new issue
Block a user