Author Topic: Permissions  (Read 735 times)

TheQuirk

  • VIP
  • Member
  • ***
  • Posts: 2,154
  • Kudos: 315
Permissions
« on: 5 December 2002, 06:50 »
This is just for future reference. . . If, lets say, I break something, but can resture all my files *without* their appropriate premissions, could I restore them automaticlly from a premission backup?

(this is what I mean:

$su -
#cd / && ls
# ls -laR > /path/to/backup/filesstem.backup

)

I realized I included in the FAQ how to do the backup thing, but I didn't include a section on how to restore using the backup because I don't know how to (and was never forced to learn.)

[edit: Just could not stand the title, it waseating into my body]

[ December 05, 2002: Message edited by: X11 / BOB: l33t h4x0r ]


voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Permissions
« Reply #1 on: 5 December 2002, 07:32 »
I don't understand. "ls" isn't going to backup anything. It just lists directory contents. If you want to do backups you use "tar", "cpio", etc. These utilities automatically back up the permissions with the files so when you restore them they maintain their original permissions (if you are root when you run the command that is). Or am I misunderstanding what you are getting at?

If you want to use the "cp" command to just copy files from one location to another then you would use the "-a" parameter to maintain permissions on the files:

Copy file:
# cp -a /sourcedir/subsourcedir /destinationdir

Create an archive file using tar:
# cd /
# tar -cvzf /destinationdir/mybackup.tar.gz sourcedir/subsourcedir

Restore all of the contents of archive:
# cd /
# tar -xvzf /destinationdir/mvbackup.tar.gz

Create a tape backup of /home using tar (if you have a SCSI tape drive):
# cd /
# tar -cvzf /dev/nrst home

[ December 04, 2002: Message edited by: void main ]

Someone please remove this account. Thanks...

TheQuirk

  • VIP
  • Member
  • ***
  • Posts: 2,154
  • Kudos: 315
Permissions
« Reply #2 on: 5 December 2002, 07:35 »
You misunderstood. I didn't explain it clearly. . .

The output of "ls -laR" is written to a file, and it lists the premissions, along with outher stuff, such as this:

-rw-rw-r--    1 glezhe   glezhe       7121 Dec  4 22:11 viewnews.cgi
-rw-rw-r--    1 glezhe   glezhe        508 Dec  4 22:11 viewnews-readme.txt
-rw-rw-r--    1 glezhe   glezhe         90 Dec  4 22:11 viewnews.tmpl

Now, I'm just curious. . . Lets say all the premissions get screwed up. Would I be able to restore them using the backed-up copy of "ls -laR" automaticlly?

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Permissions
« Reply #3 on: 5 December 2002, 07:46 »
If your files permissions have that much of a chance of getting screwed up I would suggest having a backup, in which case you could restore just the affected files and their permissions (I back up all of my critical stuff nightly).

Having said that there was a command in AIX that I used to use that could save and restore file permissions and I am pretty sure there is one in Linux but I have to think.... I'll get back to you when I think of it. I am pretty sure the RPM command uses this utility because if you have a permissions problem with any system file the "rpm -V" can tell you that there is a permissions problem and what the permissions should be. I'll get back with you.
Someone please remove this account. Thanks...

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Permissions
« Reply #4 on: 5 December 2002, 07:55 »
Ok, here's one way to do it if you have the acl utilities installed (I think most modern distros include them):

# cd /somedir
# getfacl -R . > /otherdir/somedir.acl.txt

To restore the permissions you would:

# cd /somedir
# setfacl --restore=/otherdir/somedir.acl.txt

The above will save the permissions for all files under /somedir including subdirectories into a text file called /otherdir/somedir.acl.txt. And you can modify any permissions under that directory and restore the saved permissions with the second setfacl command.

For more information on the acl commands do a:

$ man acl
$ man getfacl
$ man setfacl

I think there are other similar tools.

[ December 04, 2002: Message edited by: void main ]

Someone please remove this account. Thanks...