Figured I'd throw this into the intertubes so it's archived and maybe useful for someone else, since I couldn't find a script that did this already... -----Original Message----- From: Daevid Vincent [mailto:daevid@xxxxxxxxxx] Sent: Monday, July 13, 2009 4:06 PM To: 'svlug@xxxxxxxxxxxxxxx' Subject: RE: accidentally chown -R mysql /var/lib Well, I just wrote a little script and ran it against the three Ubuntu boxen I have access too, and then just ran the output against my own 'broken' box... ---------------------------------- 8< snip >8 ------------------------------------------- #!/usr/bin/php <?php error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); //E_WARNING because the posix_* seems to puke on symlinks ?! function rootscan($base='', &$data=array()) { $array = array_diff(scandir($base), array('.', '..')); foreach($array as $value) { $bv = $base.$value; $owner = posix_getpwuid(fileowner($bv)); $owner = $owner['name']; $group = posix_getgrgid(filegroup($bv)); $group = $group['name']; if ($owner != 'root' || $group != 'root') echo "chown ".$owner.':'.$group.' '.$bv."\n"; if (is_dir($bv)) { $data[] = $bv.'/'; $data = rootscan($bv.'/', $data); } elseif (is_file($bv)) { $data[] = $bv; } } return $data; } rootscan('/var/lib'.'/'); ?> ---------------------------------- 8< snip >8 ------------------------------------------- It produces a bunch of lines like this: vincentd@gabriel:~$ sudo ./dirfix.php chown root:polkituser /var/lib/PolicyKit chown root:polkituser /var/lib/PolicyKit/user-haldaemon.auths chown polkituser:root /var/lib/PolicyKit-public chown avahi-autoipd:avahi-autoipd /var/lib/avahi-autoipd chown root:gdm /var/lib/gdm chown libuuid:libuuid /var/lib/libuuid chown polkituser:polkituser /var/lib/misc/PolicyKit.reload chown root:mlocate /var/lib/mlocate/mlocate.db chown mysql:mysql /var/lib/mysql ... chown postfix:postfix /var/lib/postfix chown postfix:postfix /var/lib/postfix/master.lock chown root:sambashare /var/lib/samba/usershares > -----Original Message----- > From: Daevid Vincent [mailto:daevid@xxxxxxxxxx] > Sent: Monday, July 13, 2009 2:38 PM > To: 'svlug@xxxxxxxxxxxxxxx' > Subject: accidentally chown -R mysql /var/lib > > Yes, I was setting up a new Ubuntu 9.04 box for the past > couple days, and today when copying a 70GB database from an > old server to the new one, I accidentally did this (well, the > equiv of anyways): > > chown -R mysql:mysql /var/lib > > Instead of > > chown -R mysql:mysql /var/lib/mysql > > So I've "reverted" to: > > chown -R root:root /var/lib > > Does anyone know of a "script" or something that will fix all > the directories to their proper owner/group again? > > If not, I have a 9.04 box next to me that has a pristine > /var/lib tree (just not all the same packages that the new > box had). Is there some script-fu that I can run on the good > box that will show me all the owner/groups that are NOT > root:root, so I can manually adjust. Doing a random quick > poke at various directories, I don't see all that many, so I > expect the result list won't be that much. > > ...there is always the possibility of just re-installing, but > obviously I prefer not to do that if I don't have to and > waste another day re-setting stuff up (should be quicker > thanks to .tgz though) > > And before anyone decides to be a smart alec, no, of course I > hadn't done backups. ;-) But even if I did, I don't > generally backup the entire system, only the core dirs like > /etc, /home, /var/lib/mysql, etc... > http://daevid.com/content/examples/daily_backup.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php