File Permission Backup Howto?

Have you ever mistakenly changed a directory permission?

Well, I guess that happens to all once in a while(even couple of years).

So, Following is a short tutorial about how to back up your permissions for latter recovery.

The idea is very simple:
* Create a permission back up file named: myperbackup.sh (based on arg $2)
* Loop over the path to backup
* For each file store the:
chmod command and the old permission bits
chown command and the user.group

Note:
Its a good idea to place that in cron.
Belive me do it for your projects folder is a must!

The attached script will create a file which looks like this:

#!/bin/bash
echo Restore permissions of /home/m/ @ Thu Sep 10 08:42:02 IDT 2009
read -p "Do you want to restore? [y/n] " YN
if [ "$YN" != "y" ]; then
echo Abandoning restore
else
echo -n Starting restore\
echo -n .
chmod 755 "/home/m/"
chown 1000:100 "/home/m/"
echo -n .
chmod 755 "/home/m/.qt"
chown 1000:100 "/home/m/.qt"
echo -n .
chmod 644 "/home/m/.qt/qtrc"
chown 1000:100 "/home/m/.qt/qtrc"
....
....
...