reset files permissions - Server level

nservices

Verified User
Joined
Dec 11, 2008
Messages
302
Hi,
I have server that the server owner change the directory permissions (and maybe files permissions) in all the folder on the server

this server is virtual server on OpenVZ so I have access to the files
how can I restore the default permissions for the OS and DA
(DA set_permissions Script not cover it)
now all services are down, include DA

* perl scripts not works on the server, but work on the OpenVZ Main server.

Best Regards,
Star Network.
 
You prolly need to manual change each file/directory permission checking a working box.

There isnt afaik a tool for that.

A best/faster way should be backup all domains/users and create a new box...

Regards
 
Thanks for your answer
I see some tool, but it didn't work 100%

saveState.pl
Code:
my $tree = $ARGV[0];

foreach $file (`/usr/bin/find ${tree}`)
{
  chomp($file);
  (undef, $inode, $mode, undef, $uid, $gid, $undef, $size, undef, undef, undef, undef, undef) = stat($file);
  $permissions = $mode & 07777;
  printf "%i:%i:%04o:%i:%i:%s\n", $inode, $size, $permissions, $uid, $gid, $file;
}

applyState.pl
Code:
#Does not save ACL...

my $stateFile = $ARGV[0];

open(STATE_IN, "<$stateFile");

foreach $line (<STATE_IN>)
{
  chomp($line);
  my ($inode, $size, $permissions, $uid, $gid, $file) = split(':', $line, 6);
  if( -f $file )
  {
    #add inode / size check here if desired
    chmod(oct($permissions), $file);
    chown($uid, $gid, $file);
  }
}

close(STATE_IN);

################# Example #################
Code:
9:45am root@hyperion  /research/src/state_saver #>perl saveState.pl /research/src/state_saver/ > test

9:45am root@hyperion  /research/src/state_saver #>cat test
1846211:512:0755:0:0:/research/src/state_saver/
1846214:0:0644:0:0:/research/src/state_saver/test
1846213:365:0644:0:0:/research/src/state_saver/applyState.pl
1846212:332:0644:0:0:/research/src/state_saver/saveState.pl

9:45am root@hyperion  /research/src/state_saver #>l
total 10
   1846211 drwxr-xr-x   2 root     root         512 Jan 13 09:45 .
   1846210 drwxr-xr-x   3 root     root         512 Jan 13 09:30 ..
   1846213 -rw-r--r--   1 root     root         365 Jan 13 09:44 applyState.pl
   1846212 -rw-r--r--   1 root     root         332 Jan 13 09:44 saveState.pl
   1846214 -rw-r--r--   1 root     root         219 Jan 13 09:45 test

9:45am root@hyperion  /research/src/state_saver #>chmod 777 saveState.pl 

9:45am root@hyperion  /research/src/state_saver #>l
total 10
   1846211 drwxr-xr-x   2 root     root         512 Jan 13 09:45 .
   1846210 drwxr-xr-x   3 root     root         512 Jan 13 09:30 ..
   1846213 -rw-r--r--   1 root     root         365 Jan 13 09:44 applyState.pl
   1846212 -rwxrwxrwx   1 root     root         332 Jan 13 09:44 saveState.pl
   1846214 -rw-r--r--   1 root     root         219 Jan 13 09:45 test

9:45am root@hyperion  /research/src/state_saver #>perl applyState.pl test 

9:46am root@hyperion  /research/src/state_saver #>l
total 10
   1846211 drwxr-xr-x   2 root     root         512 Jan 13 09:45 .
   1846210 drwxr-xr-x   3 root     root         512 Jan 13 09:30 ..
   1846213 -rw-r--r--   1 root     root         363 Jan 13 09:46 applyState.pl
   1846212 -rw-r--r--   1 root     root         332 Jan 13 09:44 saveState.pl
   1846214 -rw-r--r--   1 root     root         219 Jan 13 09:45 test

9:46am root@hyperion  /research/src/state_saver #>

from: http://www.unix.com/shell-programmi...cript-save-restore-files-dir-permissions.html

I believe that there is more tools for it.

Best Regards,
Star Network.
 
As far as ive read those script save current status and restore saved status (saved from savestatus) to files...

You need a script that reset to default OS permissions.. thats why ive sayd i dont know any script that do this...
 
but it didn't work 100%

And what did not work?

What CP for VPS managing do you have? HyperVM?

You might want to ask your VPS provider to recover system files in your VPS, it means to restore all system files, without deleting others. And after that, you might want to run

Code:
./build all

to rebuild all required software with custombuild.


p.s. To use that script you need run the first part on a working VPS, the second part should be run your affected server.
 
Back
Top