System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

How to save and restore all the permission of the folder.

SOLVED
Go to solution
senthil_kumar_1
Super Advisor

How to save and restore all the permission of the folder.

Hi

One folder can have lot sub directories and files. and each folders and files can have different permissions (rwx).

username and groupname may vary for each subfolders.

So i want to backup (save) the current permission of the folder.

and in future i want to restore if i need.

can we do this in HP-UX?

16 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: How to save and restore all the permission of the folder.

Hi:

First, please use the term "directory" and not that other operating system's word called "folder".

Yes, you can backup and restore permissions of both files and directories.

Utilities like 'tar', 'pax', 'cpio' and 'fbackup' and 'frecover' all support this. You need to (1) read the manpages for your chosen tool; and/or (2) define which tool you want to use.

Regards!

...JRF...
Tingli
Esteemed Contributor

Re: How to save and restore all the permission of the folder.

# find /file_system -type d -exec ls -ld {} \;
UVK
Trusted Contributor

Re: How to save and restore all the permission of the folder.

As james mentioned tar, pax, cpio and fbackup and frecover all of them do what you are looking for. Choose what you want to use and have fun with it ;-)

Cheers,
uvk
-------------------------------------------
Like it or worked !! Click kudos !!
Taifur
Respected Contributor

Re: How to save and restore all the permission of the folder.

Hi Senthil,

You can backup the current permission of the folder by using tar, cpio, fbackup, frecover.

You can check man pages of tar, cpio, fbackup
Check below link for backup as follows,

http://docs.hp.com/en/5992-4616/ch03s04.html

If it helps, pls assign point.

Rgds//
Taifur
Dennis Handly
Acclaimed Contributor
Solution

Re: How to save and restore all the permission of the folder.

Do you want to save the permissions of the directory but not its contents recursively?
This may be hard for tar and cpio.
For pax(1) you can use -d.
R.K. #
Honored Contributor

Re: How to save and restore all the permission of the folder.


Hi Senthil,

As mentioned, you can use tar, pax, cpio, fbackup for taking backup of directories while conserving their attributes.

If you want to copy from one directory to another with attributes:

Using cp for smaller sizes:
# cp â pr

Using cpio:
# cd
# find . -depth | cpio -pmdv

Using tar:
# cd
# tar cf - . | ( cd new_dir ; tar xf - )


Regds,
R.K.

Don't fix what ain't broke
Suraj K Sankari
Honored Contributor

Re: How to save and restore all the permission of the folder.

Hi Santhil,
I always preferred "tar" command because its the easiest and most popular command is "tar" apart from tar you can use so many other commands like vxdump, cipo, and for full os backup ignite.

examples
1.To take backup of /tmp dir into the tape drive /dev/rmt0,
make sure current directory is / then execute the command
# tar -cvf /dev/rmt0 ./tmp

For multiple directories or files, specify the names with one by one seperated by a space.
ex : tar -cvf /dev/rmt0 ./tmp ./var ./u01

For extract "tar -xvf /dev/rmt0"
For seeing the file without extract "tar -tvf /dev/rmt0"
Suraj
Ganesan R
Honored Contributor

Re: How to save and restore all the permission of the folder.

Hi,

By default backup tools will preserve the permissions and ownership during backup and resore the same permission/ownership during restoration.

If you are using cp command to take backup across filesystems just use "-p" to preserve the permission/ownerships.
Best wishes,

Ganesh.
senthil_kumar_1
Super Advisor

Re: How to save and restore all the permission of the folder.

Hi Dennis Handly,

You are right. that want to save the permissions of the directory only but not its contents.

so pls explain me how to use the command "pax" to do the above things.

I tried but i am not able to succeed.

So pls tell me if you know that.
Dennis Handly
Acclaimed Contributor

Re: How to save and restore all the permission of the folder.

>want to save the permissions of the directory only but not its contents.

$ ll
drwxrwxr-x ... SAM1/
$ pax -v -w -f foo.tar -d SAM? # write pax
SAM1/
$ pax -v -f foo.tar # list pax
USTAR format archive
drwxrwxr-x 0 UUU GGG ... SAM1/
$ chmod go= SAM?
$ ll
drwx------ 2 UUU GGG ... SAM1/
$ pax -v -r -f foo.tar # read pax
USTAR format archive
SAM1/
$ ll
drwxrwxr-x 2 UUU GGG ... SAM1/

The permission is restored.
senthil_kumar_1
Super Advisor

Re: How to save and restore all the permission of the folder.

Hi Dennis Handly,

I am not able to revert back to original permission.

I do following things as you said.

1)First listing the existing permission.

# ll -d home
drwxr-xr-x 11 root root 248 Apr 22 05:32 home

2)I am writing permissions of /home

# pax -v -w -f foo.tar -d /home

/home
pax: ustar vol 1, 1 files, 0 bytes read, 10240 bytes written.


3)I am seeing the permissions of /home folder.

# pax -v -f foo.tar
drwxr-xr-x 2 root root 0 Apr 22 05:32 /home
pax: ustar vol 1, 1 files, 10240 bytes read, 0 bytes written.


4) changing the permission of /home directory.

# chmod 775 /home


5)checking new permissions.

# ll -d /home
drwxrwxr-x 11 root root 248 Apr 22 05:32 /home


6) reverting the old permissions.

# pax -v -r -f foo.tar
/home
pax: ustar vol 1, 1 files, 10240 bytes read, 0 bytes written.

7) But it is not changing
For example:

# ll -d /home
drwxrwxr-x 11 root root 248 Apr 22 05:32 /home


So how to solve this problem.

And i want to take the permissions of the subfolders also.



Dennis Handly
Acclaimed Contributor

Re: How to save and restore all the permission of the folder.

>I am not able to revert back to original permission.

I have no problems doing that. I have PHCO_38165.

>I want to take the permissions of the subdirectories also.

$ find SAM1 -type d | pax -w -v -f foo.tar -d
SAM1/
SAM1/SUB_deeper/
$ pax -f foo.tar -v
USTAR format archive
drwx------ 0 UUU GGG ... SAM1/
drwxrwxr-x 0 UUU GGG ... SAM1/SUB_deeper/
Suraj K Sankari
Honored Contributor

Re: How to save and restore all the permission of the folder.

Hi Senthil,

Did you tried with "tar" command its easy to use

tar -cvf test.tar testdirectiory

go to desire location and restore and for the same location you need to remove the testdirectiory then restore

tar -xvf test.tar

Suraj
Dennis Handly
Acclaimed Contributor

Re: How to save and restore all the permission of the folder.

>Suraj: Did you try with "tar" command

I don't see an option like pax's -d.
Suraj K Sankari
Honored Contributor

Re: How to save and restore all the permission of the folder.

Hi,
see the example

[root@rspc521 test]# mkdir test
[root@rspc521 test]# ll
total 4
drwxr-xr-x 2 root root 4096 May 15 11:47 test
[root@rspc521 test]# cd test
[root@rspc521 test]# touch a
[root@rspc521 test]# touch b
[root@rspc521 test]# touch c
[root@rspc521 test]# tar -cvf test.tar test
[root@rspc521 test]# ll
total 16
drwxr-xr-x 2 root root 4096 May 15 11:47 test
-rw-r--r-- 1 root root 10240 May 15 11:47 test.tar

[root@rspc521 test]# rm -Rf test

[root@rspc521 test]# tar -xvf test.tar
test/
test/a
test/b
test/c
[root@rspc521 test]# ll
total 16
drwxr-xr-x 2 root root 4096 May 15 11:47 test
-rw-r--r-- 1 root root 10240 May 15 11:47 test.tar

Suraj
senthil_kumar_1
Super Advisor

Re: How to save and restore all the permission of the folder.

Hi Suraj K Sankari,

Thanks for your reply. but if the directory size is 100GB and above. then it is not possible to copy the whole directory and restore it again.

What i am saying that we are changing some directories permission. And in future if we want to revert back the new permissions to old one. for that only i want to backup permission of the directories only but not contents.

Hi Dennis Handly,

I tried this (pax) in linux.

today i will try this is in hp-ux.