Rsync Restore all files and directories have 777 permissions

Hey there.

So I have recently run into an issue where by when I have been completing my Rsync backups with the -X option it has been failing due to a bug in RHEL that is marked WONTFIX.

Since this issue I have changed my rsync from being rsync -aAXv to just rsync -aAv and this works, However, What I didn’t know was that when I restored all my files and directories have been changed to 777 permissions.

Is there any way that I can fix this and return all files to their respective attributes?

Thanks in advances.

P.S. I restored from backup because I changes the SSD in my computer, I might be able to get back some of the files from the old drive but that would also be a hassle, Trying to find the the best of the evils here :roll_eyes:

Potentially the file system you are copying from may be ntfs or vfat. Those file systems do not save the permissions and everything copied back will have the 777 permissions.

If this is your home directory then it is possible to use find to locate the directories and change permissions, then to do the same for the files. It will not, however, directly restore the selinux contexts. That would need to be done using restorecon.
When within your home directory find . -type d -exec chmod 750 "{}" + and find . -type f -exec chmod 644 "{}" + should take care of most of that except for specific files for which you want different permissions. Then the selinux permissions can be reset by sudo restorecon -R /home

Use the man page for each of those commands to understand exactly what the command does.

4 Likes

Are the permissions correct on the backup? If so some hand written scripts could help to make the needed permission changes. If the permissions weren’t maintained as the backup was created, then Jeff’s suggestion is likely your best option.

1 Like

The permissions are not correct on the backup. However, I have just received a drive case for the old laptop SSD and I now have a copy of all the files that I would like from the old laptop SSD.

How can I go about correcting the permissions using the original files and directories?

Thanks

Do you have any software tools skills, such as being able to write scripts? If so, you’d perhaps create a file with all the current file pathnames and permissions, and all the desired pathnames and permissions, then check the current permissions for each pathname against the desired and make a correction as needed. I can help with that if you like.

1 Like

In that case I assume you will be copying from a linux file system to another linux file system. and then rsync will preserver the permissions and attributes. That will not be the case if you copy your files to an NTFS or VFAT file system.

1 Like

I do, I should note that I have solved this now as I decided just to replace all the files and directories in my home dir using rsync --fake-super -aAX --progress which transferred the files as I needed them.

However, for the sake of this thread so that others might find it useful in the future, how would you recommend that I go about solving this if I was not able to brute force the files back into the system using the program

2 Likes