Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test backing up permissions in a "SSH local" profile. #1340

Merged
merged 1 commit into from
Oct 22, 2022
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
13 changes: 10 additions & 3 deletions common/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,22 +883,29 @@ def setSymlink(self, profile_id = None, hash_id = None, tmp_mount = None):
"""
if not self.symlink:
return

if profile_id is None:
profile_id = self.profile_id

if hash_id is None:
hash_id = self.hash_id

if tmp_mount is None:
tmp_mount = self.tmp_mount
dst = self.config.snapshotsPath(profile_id = profile_id,
mode = self.mode,
tmp_mount = tmp_mount)

dst = self.config.snapshotsPath(profile_id=profile_id,
mode=self.mode,
tmp_mount=tmp_mount)
mountpoint = self.mountpoint(hash_id)

if self.symlink_subfolder is None:
src = mountpoint
else:
src = os.path.join(mountpoint, self.symlink_subfolder)

if os.path.exists(dst):
os.remove(dst)

os.symlink(src, dst)

def removeSymlink(self, profile_id = None, tmp_mount = None):
Expand Down
29 changes: 22 additions & 7 deletions common/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,11 +937,15 @@ def backupPermissions(self, sid):

Args:
sid (SID): snapshot that should be scanned

Returns:
int: Return code of rsync.
"""
logger.info('Save permissions', self)
self.setTakeSnapshotMessage(0, _('Saving permissions...'))

fileInfoDict = FileInfoDict()

if self.config.snapshotsMode() == 'ssh_encfs':
decode = encfstools.Decode(self.config, False)
else:
Expand All @@ -953,19 +957,30 @@ def backupPermissions(self, sid):

rsync = ['rsync', '--dry-run', '-r', '--out-format=%n']
rsync.extend(tools.rsyncSshArgs(self.config))
rsync.append(self.rsyncRemotePath(sid.pathBackup(use_mode = ['ssh', 'ssh_encfs'])) + os.sep)
rsync.append(
self.rsyncRemotePath(
sid.pathBackup(
use_mode=['ssh', 'ssh_encfs']
)
) + os.sep
)

with TemporaryDirectory() as d:

rsync.append(d + os.sep)

proc = tools.Execute(rsync,
callback = self.backupPermissionsCallback,
user_data = (fileInfoDict, decode),
parent = self,
conv_str = False,
join_stderr = False)
proc.run()
callback=self.backupPermissionsCallback,
user_data=(fileInfoDict, decode),
parent=self,
conv_str=False,
join_stderr=False)
rc = proc.run()

sid.fileInfo = fileInfoDict

return rc

def backupPermissionsCallback(self, line, user_data):
"""
Rsync callback for :py:func:`Snapshots.backupPermissions`.
Expand Down
3 changes: 3 additions & 0 deletions common/test/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
except ConnectionRefusedError:
sshdPortAvailable = False

SKIP_SSH_TEST_MESSAGE = 'Skip as this test requires a local ssh server, ' \
'public and private keys installed'
LOCAL_SSH = all((tools.processExists('sshd'),
os.path.isfile(PRIV_KEY_FILE),
KEY_IN_AUTH,
Expand All @@ -73,6 +75,7 @@
ON_RTD = os.environ.get('READTHEDOCS', 'None').lower() == 'true'



class TestCase(unittest.TestCase):
"""Base class for Back In Time unit- and integration testing.

Expand Down
Loading