I am trying to use rsync to copy a backup folder on a local machine to another machine daily (in case of data loss or accidental deletion). This runs as a cronjob.
I just the command
rsync -av --rsh='ssh -p90' --delete /backup/ tentbackup@mydomain.com:~/dabackup/
From the root
account on server one (tent
).
However on the first server the permissions on each of the subdirectories are set so that you can't get into them unless you are root (no execute permission on the folders), this is something I cannot change easily as it is how the backup software works.
This means that on the second server (mydomain.com
) the account tentbackup
doesn't have permission to go into the folders that rsync is creating resulting in the following errors
root@tent:~$ rsync -av --rsh='ssh -p92' --delete /backup/ tentbackup@mydomain.com:~/dabackup/
building file list ... done
03-05-11/apache/
rsync: recv_generator: mkdir "/home/tentbackup/dabackup/03-05-11/apache" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
03-05-11/bind/
rsync: recv_generator: mkdir "/home/tentbackup/dabackup/03-05-11/bind" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
03-05-11/custom/
rsync: recv_generator: mkdir "/home/tentbackup/dabackup/03-05-11/custom" failed: Permission denied (13)
etc...
I could work around this problem using root@mydomain.com
(server two
) but obviously I don't want ssh keys for the root account stored on server one
(tent
).
How do I safely allow rsync
permission to create these subfolders and files?
Even when logged into server two directly as tentbackup I cannot move into the directories or make files inside them
tentbackup@brave:~/dabackup$ cd 03-20-11/
bash: cd: 03-20-11/: Permission denied
tentbackup@brave:~/dabackup$ mkdir 03-20-11/test -p
mkdir: cannot create directory `03-20-11': Permission denied
tentbackup@brave:~/dabackup$ touch 03-20-11/test
touch: cannot touch `03-20-11/test': Permission denied
Best Answer
The correct way to do this (though it does change the permissions so you can't just restore from backup if these were important) is to add the following to your rsynccommand
Where
--no-p
disables permissions copying--no-g
disables group copying and--chmod=ugo=rwX
ensures that all non-masked bits get enabled