LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices


Reply
  Search this Thread
Old 09-10-2003, 02:40 PM   #1
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Lightbulb Creating permission restore points


I have seen a few posts lately about people accidently chmoding directories recursively and ending up not being able to access certain directories/run specific programs.

I recently had a need (for use on a webserver) to create a script that could backup permissions and restore them at a later date. I have seen other ways to do it but I chose this way since I could edit the restore file at a later date and only restore certain permissions.

For anyone that wants it - here it is:
Code:
#!/bin/bash

if [ ! $1 ] || [ ! $2 ];then
echo Please run as \"permbackup.sh /path/to/base restore-perms.sh\"
echo To add a date \"permbackup.sh /path/to/base restore-perms-`date +%F`.sh\"
else
IFS="
"
echo -n Starting to create restore file\
echo \#\!/bin/bash > $2
echo echo Restore permissions of $1 @ `date` >> $2
echo read -p \"Do you want to restore? [y/n] \" YN >> $2
echo if [ \"\$YN\" \!= \"y\" ]\; then >> $2
echo echo Abandoning restore >> $2
echo else >> $2
echo echo -n Starting restore\\\ >> $2
for file in `find $1`;do
echo -n .
echo echo -n . >> $2
type=`stat --format="%F" $file`
if [ "$type" != "Symbolic Link" ];then
echo chmod `stat --format="%a" $file` \"$file\" >> $2
echo chown `stat --format="%u:%g" $file` \"$file\" >> $2
fi
done
echo echo -e \\\\nRestore complete >> $2
echo fi >> $2
chmod 700 $2
echo -e \\n\\nRestore point of permissions for $1 @ `date` created.\\n\\nPlease execute \"$2\" to restore permissions.\\n
fi
As root - save this as a file called "permbackup.sh" in /usr/local/bin then chmod it 755:
chmod 755 /usr/local/bin/permbackup.sh

Running "permbackup.sh" will give you basic usage instructions. I have only tested this on RedHat 9 but it "should" work on any system where stat uses custom output formats.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Acroread: libJP2K.so: cannot restore segment prot after reloc: Permission denied pavodive Linux - Security 8 02-25-2009 01:52 PM
How do I create system restore points similar to XP. MurX Linux - Software 3 10-24-2005 04:29 AM
How do I avoid creating lots of mount points? adrian_stephens Linux - General 5 04-16-2005 02:46 PM
creating user limiting permission nistelrooy Linux - Security 4 02-10-2005 01:07 PM
creating mount points and is the data safe if i change system JMK Linux - Newbie 4 01-22-2004 09:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories

All times are GMT -5. The time now is 04:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration