You can use stat
to query the mode on your backup file, and chmod
to update your working files. Do this in a loop, with a little string manipulation, and you have a solution. Something like this should work to copy the permissions:
# path to the top level of the backup
backup_dir=/path/to/backup/dir
# path to the directory of files that you want to restore
# permissions on.
dir=/path/to/working/dir
find "$backup_dir" |
while read backup_file
do
new_file="$dir${backup_file#$backup_dir}"
chmod --reference="$backup_file" "$new_file"
done
Note that this won't work well if your filenames contain the newline character (but thats's pretty rare). Also, it's untested, so you may want to do a "dry-run" by changing 'chmod' to 'echo chmod', so it just prints what it would do.
rsync -a
orcp -a
, whichever's available, to have the permissions preserved in the first place ;)