LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-05-2016, 12:28 PM   #1
grigory
Member
 
Registered: Oct 2015
Posts: 133

Rep: Reputation: Disabled
Which is the right way to issue a tar command when you restore your system


Hello!

I've recently created a tarball backup of my Ubuntu system (/ and /home partitions both ext4).
When I was creating a backup I booted off Live DVD and I used a tar command.
Now I wonder which would be the best way to untar the gzipped archive in order to restore the system. More specifically, if I should add --numeric-owner switch at the end of the tar command? I heard that it might be needed to preserve an original ownership permissions. Otherwise, I would get those from a storage media and there could be a mismatch.
On the other hand, both times I use Live DVD to boot from, so maybe it's irrelevant in my particular case? Please let me know. Thanks!
 
Old 02-05-2016, 12:40 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
It depends on how you made the backup (you said A tar command, we need to know WHAT tar command), what part of the filesystem you backed up, and what you want to recover.
 
Old 02-05-2016, 12:54 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
In addition:
Quote:
Originally Posted by grigory View Post
More specifically, if I should add --numeric-owner switch at the end of the tar command? I heard that it might be needed to preserve an original ownership permissions. Otherwise, I would get those from a storage media and there could be a mismatch.
If your tarball includes /etc then you have the account / UID mappings (/etc/passwd, /etc/group) so if you untar with "-C /" there should be no mismatch?
 
Old 02-06-2016, 08:18 AM   #4
grigory
Member
 
Registered: Oct 2015
Posts: 133

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
It depends on how you made the backup (you said A tar command, we need to know WHAT tar command), what part of the filesystem you backed up, and what you want to recover.
In my first post I've written what part of FS I backed up. "/ and /home partitions both ext4)"
Also I've written the answer to your question as to what I want to recover. "Now I wonder which would be the best way to untar the gzipped archive in order to restore the system"
If you're asking what exactly I typed when I originally created my tarball, then it's this command:

Code:
sudo tar -cvzpf /mnt/backup/root.tar.gz /mnt/root/
sudo tar -cvzpf /mnt/backup/home.tar.gz /mnt/home/
 
Old 02-06-2016, 08:21 AM   #5
grigory
Member
 
Registered: Oct 2015
Posts: 133

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
In addition:

If your tarball includes /etc then you have the account / UID mappings (/etc/passwd, /etc/group) so if you untar with "-C /" there should be no mismatch?
Yes, my tarball does include /etc directory. It includes EVERYTHING in root. I haven't excluded anything in either / or /home partitions. Are you asking or answering? I've noticed a question mark at the end of your sentence.
 
Old 02-06-2016, 09:38 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by grigory View Post
Are you asking or answering? I've noticed a question mark at the end of your sentence.
Answering. The question mark is an invitation for those who have experienced otherwise to share.
 
Old 02-06-2016, 09:43 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by unSpawn View Post
If your tarball includes /etc then you have the account / UID mappings (/etc/passwd, /etc/group) so if you untar with "-C /" there should be no mismatch?
That's true if you are currently running the same system that you are restoring. That's unlikely if you are doing a full restore. When you are running from some recovery medium (which might not even be the same OS), tar will try to preserve user names by mapping those names to UIDs using the /etc/passwd of whatever system is currently running. If some of those are different from the system you are restoring, it will cause trouble. So yes, you do want to use the "--numeric-owner" option.

The tar manpage is almost totally uninformative about that option. The info page is better and describes situations where the option should be used, but describes that option primarily in the context of creating the archive, and just one paragraph indicates it is also effective for extraction:
The `--numeric-owner' option allows (ANSI) archives to be written without user/group name information or such information to be ignored when extracting. It effectively disables the generation and/or use of user/group name information. This option forces extraction using the numeric ids from the archive, ignoring the names.

This is useful in certain circumstances, when restoring a backup from an emergency floppy with different passwd/group files for example. It is otherwise impossible to extract files with the right ownerships if the password file in use during the extraction does not match the one belonging to the file system(s) being extracted. This occurs, for example, if you are restoring your files after a major crash and had booted from an emergency floppy with no password file or put your disk into another machine to do the restore.
 
2 members found this post helpful.
Old 02-06-2016, 11:50 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
...and there you have it. Thanks rknichols.
 
Old 02-06-2016, 06:45 PM   #9
grigory
Member
 
Registered: Oct 2015
Posts: 133

Original Poster
Rep: Reputation: Disabled
Thank you all for your replies!

Yes, unfortunately few know about --numeric-owner option and it's not well documented. I personally found out about it here:

https://www.youtube.com/watch?v=KTayZIou-1M

Towards the end of the clip the author puts it when he does a restore (untarring). But when he was creating the tarball, he didn't use that option at the end of the tar command. You know, some say that --numeric-owner should be used when you create the tarball...

The old Ubuntu installation would be deleted and wiped (zeroed out). After that, there would be a new formatting (though into the same ext4 FS). Same hardware. I understand that it's what you call NOT the same system, right?

Okay, so I do have to use --numeric-owner at the end of the tar command when restoring (even though I didn't use that switch when I was creating the archive). If that's correct, then the question is solved.
 
Old 02-06-2016, 07:07 PM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by grigory View Post
Okay, so I do have to use --numeric-owner at the end of the tar command when restoring (even though I didn't use that switch when I was creating the archive). If that's correct, then the question is solved.
Using --numeric-owner when restoring is sufficient. It blocks use of the user name data in the archive, so tar acts just as though you had never stored it there when creating the archive.
 
1 members found this post helpful.
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tar: restore only non-hidden files during a restore of /home Alan_ Linux - Newbie 4 05-25-2014 06:10 PM
system restore from tar - Virtualbox SNAFU after update xv_biker1 Linux - Newbie 1 07-27-2013 09:47 AM
Backup and restore system.... tar.gz? lebabyg Linux - General 10 09-28-2007 09:16 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:10 PM.

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