snap-sync
snap-sync copied to clipboard
snap-sync --sudo: "rsync: mkstemp failed: Permission denied (13)"
Trying to do the initial backup of my root subvol with the following command...
sudo snap-sync -r storage --sudo
...produced the following error:
...
Performing backups...
Sending first snapshot for 'root' configuration...
At subvol //.snapshots/298/snapshot
7,88GiO 2:15:33 [1016KiB/s] [ <=> ]
rsync: mkstemp "/home/zoddo/LAPTOP_BACKUP/root/298/.info.xml.stGXBy" failed: Permission denied (13)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1330) [sender=v3.2.3]
Exited due to error on line 501.
exit status: 23
command: rsync -avzq "$new_info" "$remote":"$backup_location"
bash line: 0
function name:
The remote name storage
is an alias defined in /root/.ssh/config, which also forces the username zoddo
, hence the use of --sudo
.
As I understand, it tried to rsync the file with the remote user zoddo
, but it didn't had the permission because the parent directory was created by root (through sudo).
I think this can be fixed by something like rsync --rsync-path="sudo rsync"
, but maybe there is a better way.
I managed to fix the issue with the following change:
--- /usr/bin/snap-sync 2021-01-30 09:37:09.000000000 +0100
+++ ./snap-sync 2021-06-02 13:56:40.222397205 +0200
@@ -497,10 +497,15 @@
if [[ -z $remote ]]; then
cp "$new_info" "$backup_location"
else
+ remote_rsync="rsync"
+ if [[ $sudo -eq 1 ]]; then
+ remote_rsync="sudo rsync"
+ fi
+
if [[ -z $port ]]; then
- rsync -avzq "$new_info" "$remote":"$backup_location"
+ rsync -avzq --rsync-path="$remote_rsync" "$new_info" "$remote":"$backup_location"
else
- rsync -avzqe "ssh -p $port" "$new_info" "$remote":"$backup_location"
+ rsync -avzqe "ssh -p $port" --rsync-path="$remote_rsync" "$new_info" "$remote":"$backup_location"
fi
fi
I'm not a bash expert, there is probably a cleaner way to do this.