Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
on a certain folder, but did it to / by mistake. I ctrl+c'd pretty quick, but I think it did some damage cause now I get an error on one of my webpages (I'm running apahce and mysql).
The error is:
SQLSTATE[HY000]: General error: 1 Can't create/write to file '/tmp/#sql_5916_0.MYI' (Errcode: 13)
When trying to install magento
Last edited by littlegreywings; 03-20-2009 at 08:11 AM.
The best bet could be to reinstall ALL the packages in your system, if your package manager allows that at all, if not I guess that everything will be fixed with the time as packages get updated.
The most important bit if you are running servers of any kind is to revise by hand the permissions in your server directories and files, and in everything under /home and /etc.
By the way, I see this same problem regularly but I've never seen anyone doing a backup or the file permissions, it could be a worthy idea to consider if you are afraid of mistakes like these. I never though of this myself, but the idea just came to me and it would be very simple to do so. Something like the following code should backup all the permissions in your system and save them into a plain text file, that you can use for either future reference or even to restore them all using a simple loop to feed chmod:
Code:
find /path/to/ -exec stat --format="%a %n" "{}" \; > chmod.txt
You could even compress that file and since it's a txt file it shouldn't take a lot of space.
Just a random idea I had. Not sure if anyone will care about it
Just a random idea I had. Not sure if anyone will care about it
I think it's a very good idea, actually. Maybe you could elaborate some more on what steps to take to successfullybackup and restore file perms. I'd use it
I think it's a very good idea, actually. Maybe you could elaborate some more on what steps to take to successfullybackup and restore file perms. I'd use it
grtz,
Marvelade
Well, let's rescue the line I posted above:
Code:
find /path/to/ -exec stat --format="%a %n" "{}" \; > chmod.txt
Now, let's piece it:
Code:
find /path/to/
This will look into /path/to (change by whatever path you wish, but it must exist) for files of any kind.
Code:
-exec stat --format="%a %n" "{}" \;
This will run "stat" on each one of the found files. What this command will do is to print the permissions and file name for each found file or directory.
Code:
> chmod.txt
Will store the results into a plain text file called "chmod.txt". You can try this yourself, just change /path/to/ by any path in your home, to test. The command doesn't write or erase anything, except in chmod.txt. Then you can open chmod.txt with any text editor to see its contents, you will see two columns, the first one are permissions, the second column is the file name.
This information could be used in these cases to restore the permissions either manually, or using a self made script that reads from this file, and chmods everything accordingly.
I don't know if some serious tool exist for this, but seeying how amazingly simple would be to develop one and the number of persons that ask this same question from time to time here and in another forums, I am surprised that I have never heard of such a tool. And I suspect that maybe it doesn't exist, which is strange.
This is just a quick idea, but it would be simple enough to implement it even with shell scripting. The simples case would be this:
Code:
while read LINE; do PERMS=${LINE%% *}; FILE=${LINE#* }; chmod $PERMS "$FILE"; done < chmod.txt
This will read lines from chmod.txt, separate the permissions from the file names, and issue a chmod command with that info, one chmod per file, restoring the permissions that were saved previously in chmod.txt.
A simple backup system for file permissions. I can't see any downside to using this, BUT if you decide to use this, make your tests. I don't wanna feel responsible if my oneliners fry your pc or kill your kitten hehe
EDIT: Fixed find command
EDIT: Fixed line to restore
Last edited by i92guboj; 03-20-2009 at 10:47 AM.
Reason: fixed find commands
or you could use R1Soft hot copy software which is free. the software allows you to take a snapshot of the system before making changes, and once the changes are made you can always revert back to the point before the change all on the CLI.
I do periodic (daily) / and /home backups using rsync. Rsync copies permissions.
So, faced with this disaster, I could either copy back the rsync'ed files to change the permissions, or I could construct the necessary permissions file as previously suggested, then use it to make repairs.
I can't speak to all the backup programs out there, but I would expect that most would also backup permissions automatically.
By the way, I see this same problem regularly but I've never seen anyone doing a backup or the file permissions, it could be a worthy idea to consider if you are afraid of mistakes like these. I never though of this myself, but the idea just came to me and it would be very simple to do so. Something like the following code should backup all the permissions in your system and save them into a plain text file, that you can use for either future reference or even to restore them all using a simple loop to feed chmod:
Code:
find /path/to/ -exec stat --format="%a %n" "{}" \; > chmod.txt
You could even compress that file and since it's a txt file it shouldn't take a lot of space.
Just a random idea I had. Not sure if anyone will care about it
I can't believe I've never seen this before either. I've since added it to my daily backup script (with some refinements, namely multiple directories as input) and now I can be sure to have all the critical system permissions saved every day. Incidentally, the bzipped files come to a whopping 89.4K! Well worth the space if you ask me
watch out for symlinks, stat will return 777 for them, but if you use that value later via chmod it will change the permissions on the file/directory it points to, not the symlink.
So,
Code:
find /path/to ! -type l -exec stat --format="%a %n" "{}" \; >perms.backup
Last edited by GazL; 03-20-2009 at 01:03 PM.
Reason: spelling.
This is an interesting thread because I once did a chown -r tred:tred .* as root from my home directory and wondered (too late!!) why it was taking more than a moment to complete (think about it).
I reinstalled and I learnt to be better with backups.
@pwc101,
It might be thoughtful to post your refinements to i92guboj's script here.
watch out for symlinks, stat will return 777 for them, but if you use that value later via chmod it will change the permissions on the file/directory it points to, not the symlink.
So,
Code:
find /path/to ! -type l -exec stat --format="%a %n" "{}" \; >perms.backup
Good catch, well spotted and corrected. That could be a security breach so yes, it's an important thing.
Quote:
Originally Posted by rweaver
With great power comes great responsibility-- I suggest always running find with -exec with an echo first
Code:
find . -type d -exec echo chmod 755 {} \;
I always advice that as well. A simple "echo" thrown in the middle can be used to make sure of what the results would be. Then if you agree you can remove it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.