LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-12-2007, 02:54 AM   #1
leebrent
Member
 
Registered: Oct 2007
Location: Nanaimo
Distribution: Red Hat 5
Posts: 39

Rep: Reputation: 15
Backup Restore: UID & GID are present


Hello,

I have restored a backup of some files onto my server. The server is no empty of users, but the backups are restored using the right UID's and GID's. Is there a trick to recreating all the users and associating them with their UID's and GUID's easily?

Here is an example:

drwxrwx--x 3 3039 3039 4096 Oct 23 10:56 group13
drwxrwx--x 3 3040 3040 4096 Oct 23 10:56 group14
drwxrwx--x 3 3041 3041 4096 Oct 23 10:56 group15
drwxrwx--x 3 3042 3042 4096 Oct 23 10:56 group16
drwxrwx--x 3 3043 3043 4096 Oct 23 11:12 group17
drwxrwx--x 3 3044 3044 4096 Oct 23 10:56 group18
drwxrwx--x 3 3045 3045 4096 Oct 23 10:56 group19
drwxrwx--x 3 3028 3028 4096 Oct 23 10:55 group2
drwxrwx--x 3 3046 3046 4096 Oct 23 10:56 group20
drwxrwx--x 3 3029 3029 4096 Oct 23 10:55 group3
drwxrwx--x 3 3030 3030 4096 Oct 23 10:55 group4
drwxrwx--x 3 3031 3031 4096 Oct 23 10:56 group5
drwxrwx--x 3 3032 3032 4096 Oct 29 12:11 group6
drwxrwx--x 3 3033 3033 4096 Oct 23 11:17 group7
drwxrwx--x 3 3034 3034 4096 Oct 23 10:56 group8
drwxrwx--x 3 3035 3035 4096 Oct 23 10:56 group9


At one time, 3039 = group13:group13. Any help would be greatly appreciated, does someone already have a script?

--B
 
Old 11-12-2007, 04:50 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If you had also backed up the /etc/passwd & /etc/shadow files, you could restore them somewhere and extract the regular users and then append those lines to your current files.

This bit isn't tested. I just saved your sample to a file and used awk to display the uid, gid and user fields. This will create inactive accounts (no passwords) disabled with "!" in the passwd field.
Code:
while read uid gid user; do
   groupadd -g=$gid $user 
   adduser -u=$uid -g=$gid -f $user
done < <(ls -ld | awk '{print $3, $4, $9}' )

Last edited by jschiwal; 11-12-2007 at 04:52 AM.
 
Old 11-12-2007, 09:21 AM   #3
leebrent
Member
 
Registered: Oct 2007
Location: Nanaimo
Distribution: Red Hat 5
Posts: 39

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
If you had also backed up the /etc/passwd & /etc/shadow files, you could restore them somewhere and extract the regular users and then append those lines to your current files.

This bit isn't tested. I just saved your sample to a file and used awk to display the uid, gid and user fields. This will create inactive accounts (no passwords) disabled with "!" in the passwd field.
Code:
while read uid gid user; do
   groupadd -g=$gid $user 
   adduser -u=$uid -g=$gid -f $user
done < <(ls -ld | awk '{print $3, $4, $9}' )

I have the shawdow and passwd files here in my backup. So I can just append the lines for the regular users to the end of the existing files and that will be that?
 
Old 11-12-2007, 02:09 PM   #4
leebrent
Member
 
Registered: Oct 2007
Location: Nanaimo
Distribution: Red Hat 5
Posts: 39

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by leebrent View Post
I have the shawdow and passwd files here in my backup. So I can just append the lines for the regular users to the end of the existing files and that will be that?

I ended up using this script, thanks to your information. I was able to build it:



#This is only useful if authenication takes place from an external source like LDAP, and the user does not have a password stored on the local machine.

ls -la /home > USERS
cat USERS | awk '{print "groupadd -g", $4, $9}' > part1.sh
cat USERS | awk '{print "useradd -u", $3, $9, "-g", $9 }' >> part1.sh
chmod 775 part1.sh
echo "Now go check Part1.sh, and remove any bad users"
echo "."
echo "Once checked, then run ./part1.sh"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what is uid and gid rmanocha Linux - Software 9 08-18-2008 11:03 PM
uid,gid from proc sanjaykhuntia Linux - Enterprise 1 10-28-2007 07:50 PM
What is my uid/gid? Jeebizz Slackware 2 11-22-2005 11:39 AM
vpopmail:- How can we efficiently use uid & gid amit_28oct Linux - Networking 4 09-30-2004 01:02 AM
changing uid, gid zeke1955 Linux - General 4 01-09-2004 11:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration