Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/borg/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,14 +1025,19 @@ def chunk_processor(data):
for chunk in item.chunks:
cache.chunk_incref(chunk.id, dummy_stats, size=chunk.size)

def process_stdin(self, path, cache):
uid, gid = 0, 0
def process_stdin(self, path, cache, mode, user, group):
uid = user2uid(user)
if uid is None:
raise Error("no such user: %s" % user)
gid = group2gid(group)
if gid is None:
raise Error("no such group: %s" % group)
t = int(time.time()) * 1000000000
item = Item(
path=path,
mode=0o100660, # regular file, ug=rw
uid=uid, user=uid2user(uid),
gid=gid, group=gid2group(gid),
mode=mode & 0o107777 | 0o100000, # forcing regular file mode
uid=uid, user=user,
gid=gid, group=group,
mtime=t, atime=t, ctime=t,
)
fd = sys.stdin.buffer # binary
Expand Down
12 changes: 11 additions & 1 deletion src/borg/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
from .helpers import dash_open
from .helpers import umount
from .helpers import msgpack, msgpack_fallback
from .helpers import uid2user, gid2group
from .nanorst import rst_to_terminal
from .patterns import ArgparsePatternAction, ArgparseExcludeFileAction, ArgparsePatternFileAction, parse_exclude_pattern
from .patterns import PatternMatcher
Expand Down Expand Up @@ -524,9 +525,12 @@ def create_inner(archive, cache):
for path in args.paths:
if path == '-': # stdin
path = args.stdin_name
mode = args.stdin_mode
user = args.stdin_user
group = args.stdin_group
if not dry_run:
try:
status = archive.process_stdin(path, cache)
status = archive.process_stdin(path, cache, mode, user, group)
except BackupOSError as e:
status = 'E'
self.print_warning('%s: %s', path, e)
Expand Down Expand Up @@ -3408,6 +3412,12 @@ def define_archive_filters_group(subparser, *, sort_by=True, first_last=True):
help='do not load/update the file metadata cache used to detect unchanged files')
subparser.add_argument('--stdin-name', metavar='NAME', dest='stdin_name', default='stdin',
help='use NAME in archive for stdin data (default: "stdin")')
subparser.add_argument('--stdin-user', metavar='USER', dest='stdin_user', default=uid2user(0),
help='set user USER in archive for stdin data (default: %(default)r)')
subparser.add_argument('--stdin-group', metavar='GROUP', dest='stdin_group', default=gid2group(0),
help='set group GROUP in archive for stdin data (default: %(default)r)')
subparser.add_argument('--stdin-mode', metavar='M', dest='stdin_mode', type=lambda s: int(s, 8), default=STDIN_MODE_DEFAULT,
help='set mode to M in archive for stdin data (default: %(default)04o)')

exclude_group = define_exclusion_group(subparser, tag_files=True)
exclude_group.add_argument('--exclude-nodump', dest='exclude_nodump', action='store_true',
Expand Down
4 changes: 4 additions & 0 deletions src/borg/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
# default umask, overridden by --umask, defaults to read/write only for owner
UMASK_DEFAULT = 0o077

# default file mode to store stdin data, defaults to read/write for owner and group
# forcing to 0o100XXX later
STDIN_MODE_DEFAULT = 0o660

CACHE_TAG_NAME = 'CACHEDIR.TAG'
CACHE_TAG_CONTENTS = b'Signature: 8a477f597d28d172789f06886806bc55'

Expand Down