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 argparse
|
||||||
import gzip
|
import gzip
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import tarfile
|
import tarfile
|
||||||
@@ -8,6 +9,7 @@ import zlib
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from pathlib import Path, PurePosixPath
|
from pathlib import Path, PurePosixPath
|
||||||
|
from shutil import copyfileobj
|
||||||
|
|
||||||
from .domain_names import canonical_domain
|
from .domain_names import canonical_domain
|
||||||
from .mail_node import MailboxSpec
|
from .mail_node import MailboxSpec
|
||||||
@@ -259,6 +261,17 @@ def backup_members(archive):
|
|||||||
check_tar_padding(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):
|
def inspect_backup(path):
|
||||||
inventory = BackupInventory()
|
inventory = BackupInventory()
|
||||||
with open_backup(path) as archive:
|
with open_backup(path) as archive:
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import os
|
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import copyfileobj
|
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
from .directadmin import (
|
from .directadmin import (
|
||||||
DOCUMENT_ROOTS,
|
DOCUMENT_ROOTS,
|
||||||
BackupInventory,
|
BackupInventory,
|
||||||
backup_members,
|
backup_members,
|
||||||
|
copy_member,
|
||||||
member_path,
|
member_path,
|
||||||
open_backup,
|
open_backup,
|
||||||
)
|
)
|
||||||
@@ -105,14 +104,3 @@ def copy_website(backup, domain, source_root, destination, *, on_copy=None):
|
|||||||
"bytes": total_bytes,
|
"bytes": total_bytes,
|
||||||
"skipped_non_regular_entries": skipped,
|
"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 pathlib import Path
|
||||||
from tempfile import NamedTemporaryFile, TemporaryDirectory
|
from tempfile import NamedTemporaryFile, TemporaryDirectory
|
||||||
|
|
||||||
from .directadmin import backup_members, member_path, open_backup
|
from .directadmin import backup_members, copy_member, member_path, open_backup
|
||||||
from .directadmin_website import copy_member
|
|
||||||
from .node_files import check_root_file, require_root_directory
|
from .node_files import check_root_file, require_root_directory
|
||||||
from .web_node_apply import (
|
from .web_node_apply import (
|
||||||
SitePaths,
|
SitePaths,
|
||||||
|
|||||||
Reference in new issue
Block a user