How to Undo Chgrp Command!?

Posted on 2008-10-08
Medium Priority
Last Modified: 2013-11-15
Messed up.

I managed to chgrp on everything on my ubuntu webserver via SSH.

I wanted to chgrp recursively on all the files in the current directory I was issuing the command. Unfortunately it isnt relative and providing a '/' as the location sent the server off to change the group of every file on the server.

Needless to say, the server is now messed up... we cannot take orders on our website and we cannot receive emails. Theres probably many more implications that we have not found.

So the question is... how can this be fixed.

I have contacted our dedicated server provider and they are having trouble too... apparently the backup we pay for does not cover group permissions?  Strange.

So any one have any ideas of how to restore group permissions?  Owner permissions are still inatact.

Any thoughts appreciated.
Question by:manicwaszoot
LVL 19

Expert Comment

ID: 22668749
what did you change everything to?

You could change everything to `root`, ok it's not ideal but it may help you get out of a fix for a few minutes...
LVL 40

Expert Comment

ID: 22668783
can they provide you with a listing of the files and dir on the tapes / backups? what I understood from you is that you changed the group ownership and not the group permissions!

e.g. I took tar backup of my home dir then did

tar -tvf tarfile

and got something like

drwxr-xr-x omar/omar         0 2007-11-24 09:13 ./.config/
-rw-r--r-- omar/omar         5 2007-11-24 09:13 ./.config/user-dirs.locale
-rw------- omar/omar       631 2007-11-24 09:13 ./.config/user-dirs.dirs
-rw------- omar/omar      1991 2008-10-07 20:27 ./.bash_history
-rw------- omar/omar       256 2007-11-24 09:13 ./.pulse-cookie
-rw-r--r-- omar/omar       124 2007-08-31 18:20 ./.bashrc
drwx------ omar/omar         0 2007-11-24 09:13 ./.gnome2_private/
drwxr-xr-x omar/omar         0 2008-06-02 16:44 ./.wapi/
drwxrwsrwx omar/omar         0 2008-04-26 16:15 ./test/
-rw-rw-r-- omar/omar         0 2008-04-26 16:14 ./test/f
-rw-rw-r-- omar/omar         0 2008-04-26 16:15 ./test/ff
drwxr-xr-x omar/omar         0 2007-11-24 09:13 ./Videos/
-rw-rw-r-- omar/omar       131 2008-06-02 16:37 ./.gtk-bookmarks
LVL 19

Expert Comment

ID: 22668806
For info, there is no `undo` command, it would probably need to be done manually.

If this was Redhat or another rpm based install I'd write a script from the query package information to rebuild the owner/group information, alas I've no idea what the equivalent apt-get commands would be to list the information.
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

LVL 20

Assisted Solution

edster9999 earned 498 total points
ID: 22668889
I would perform a backup of the data on the server(s) and then a fresh install.
This will get the rights / owners back on all the software.
Putting the group owners back on the data should be far easier.
LVL 40

Expert Comment

ID: 22668918
Hi jools,

the problem is not only with the group ownership of installed packages files and directories, it includes those created and developed in house. But your idea will be good and will help to some extent to get a working system.
LVL 19

Expert Comment

ID: 22668957
Thx Omar, absolutely agree...

I was a little concerned when manic said the server was messed up and they couldnt take orders or send email... not good for the job prospects!

Do you know apt-get? I'm a little rusty.

Like the idea about the tar btw, could knock up another script for that too!
LVL 40

Accepted Solution

omarfarid earned 501 total points
ID: 22669363
LVL 19

Expert Comment

ID: 22669479
I guess we need more feedback from manic.

I'm wondering if dpkg can be used to list all the packages installed on the system and also all the files with permissions on the system, we could then sort out a quick script to strip out the information and run a chgrp on the lot.

LVL 40

Expert Comment

ID: 22669706
is rpm available on your system?

Author Comment

ID: 22669731
Thanks for the comments...

The email is back up but we have closed shop, with the rest of the site working bar checkout.

We have opted to migrate to a new server, which has a fresh build. The server is an upgrade so thats something I suppose.

We will then move the site data across with correct permissions from the backup.

So the worst of it is, no online orders for a number of hours.

Who would of thought chgrp command could wreak such havoc. It would be nice if there was a 'Are you sure you wish to ....'  prompt before executing...   I realised just after I hit enter that I may be chgrp'ing more than I intended.

Not a good day!

So, in order to learn from mistakes and take measures to stop this happening again. How can I back up all the files on my new server once I have finished setting it up?  I dont trust the way our provider does backups anymore.  Can you backup everything into a TAR, keeping all Group and Owner permissions?

LVL 19

Assisted Solution

jools earned 501 total points
ID: 22669807
> It would be nice if there was a 'Are you sure you wish to ....'  prompt before executing...  

Yup, we've all wondered that just after we press enter sometimes!

> Can you backup everything into a TAR, keeping all Group and Owner permissions?

Yes... tar cvf <device_or_file> <directory>
man tar for more info.

You could create aliases for chgrp and chown to run a script if you want a bit more work....
LVL 40

Expert Comment

ID: 22669810
Yes , tar can do that and check the man page of tar on your system (man tar) for -p option.

It will be nice that you do periodical backup to a stand by system (if have cash for that).

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Welcome back to our beginners guide of the popular Unix tool, cron. If you missed part one where we introduced this tool, the link is below. We left off learning how to build a simple script to schedule automatic back ups. Now, we’ll learn how to se…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question