Allow removing remote old backups with sudo if possible

If allowed by the remote server, try using sudo to remove
old backups (rm needs to be allowed in sudoers to run
without password)
This commit is contained in:
2023-10-15 15:39:06 +02:00
parent 77661c0964
commit 9390cd2de8
3 changed files with 18 additions and 12 deletions

View File

@ -229,7 +229,10 @@ class Backup:
dirs.sort()
for i in range(n_backup - self.keep):
_, _, stderr = self._ssh.exec_command(f'rm -r "{self.output}/simple_backup/{dirs[i]}"')
if self.remote_sudo:
_, _, stderr = self._ssh.exec_command(f'sudo rm -r "{self.output}/simple_backup/{dirs[i]}"')
else:
_, _, stderr = self._ssh.exec_command(f'rm -r "{self.output}/simple_backup/{dirs[i]}"')
err = stderr.read().decode('utf-8').strip().split('\n')[0]