Transfer Server Permissions
Sep 17, 2012 · 1 minute readCategory: linux
So sometimes you might have a restored backup without the correct permissions (whether that be because the backup didn’t store the permissions, the file system refused to take them, or you simply forgot to add the -p flag to tar!) and you want to copy the permissions from one machine to another.
Here’s a little script to do just that that we found whilst browsing the internet to do just that (uses perl and find) :-
find / -type f -o -type d 2>/dev/null | while read FILE; do perl -le'
printf "chmod %o \"%s\"\n", 07777 & (stat)[2], $_
for @ARGV
' "$FILE"; done > /tmp/file_perms.sh
If you run that on the server with the correct permissions, then transfer the file to the server with the wrong permissions and run the file with the following command, it will fix the perms on that server :-
sh /tmp/file_perms.sh
Which may save a lot of transfer time restoring a new backup.