LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-24-2014, 04:55 PM   #1
Alan_
LQ Newbie
 
Registered: Dec 2011
Location: New York, NY
Distribution: Linux Mint LXDE
Posts: 5

Rep: Reputation: Disabled
tar: restore only non-hidden files during a restore of /home


I am stuck for a solution to this seemingly simple problem: restore all non-hidden files and directories to all /home directories found in in a full-system tarball.

I created this test environment in my home directory to mimic a /home restore from a backup directory in /:

I made and populate the following directories:

~/ttar
~/ttar/td1 (several dummy files, some links, some hidden)
~/ttar/td1/root (several dummy files, some links, some hidden)
~/ttar/td1/bin (several dummy files, some links, some hidden)
~/ttar/td1/usr (several dummy files, some links, some hidden)
~/ttar/td1/home/alan/.config (same as ~/.config)
~/ttar/td1/home/alan/.gconfig (same as ~/.gconfig)
~/ttar/td1/home/alan/ (numerous dummy files, some links, some hidden)

and ~/ttar/td1/backups (to simulate a backup archive in /)

Moving into ~/ttar/td1/backups I created a tar archive simulating a full system archive using the command:

tar -zxvpf ttar.tar.gz --directory=../ .

Then, for several hours, I repeatedly erased everything in ~/ttar/td1 (except ~/ttar/backups) during research and trial-and-error; this the partial solution I came up with:

tar -xzvpf ttar.tar.gz --directory=../ ./home

The partial solution yields only the original ~/ttar/td1/home/alan but with unwanted hidden files.

Can anyone tell me how to avoid restoring those last few hidden files?


TIA

Last edited by Alan_; 05-25-2014 at 03:35 AM.
 
Old 05-24-2014, 11:16 PM   #2
darthaxul
Member
 
Registered: Aug 2008
Distribution: Devuan; Gentoo; FreeBSD
Posts: 236

Rep: Reputation: 19
you can run find .* and it will list all the hidden files/folders
 
Old 05-25-2014, 03:52 AM   #3
Alan_
LQ Newbie
 
Registered: Dec 2011
Location: New York, NY
Distribution: Linux Mint LXDE
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by darthaxul View Post
you can run find .* and it will list all the hidden files/folders
Yup, that will list all hidden files and folders in and below a directory in an existing file system, but even redirecting the output to a file, and using that file as input to tar to exclude files from the restore, will not stop tar from restoring hidden files in the archive tarball that aren't on the system yet.

By the by, I altered my 'nearest solution' tar command posted above as it was the wrong example.


Regards,

Last edited by Alan_; 05-25-2014 at 03:56 AM.
 
Old 05-25-2014, 01:19 PM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by Alan_ View Post
Moving into ~/ttar/td1/backups I created a tar archive simulating a full system archive using the command:

tar -zxvpf ttar.tar.gz --directory=../ .
That command extracts from a tar archive. It does not create one.
Quote:

Then, for several hours, I repeatedly erased everything in ~/ttar/td1 (except ~/ttar/backups) during research and trial-and-error; this the partial solution I came up with:

tar -xzvpf ttar.tar.gz --directory=../ ./home
I'm having trouble figuring out just what you did, but this should extract everything except the dotfiles and directories:
Code:
tar -zxvpf ttar.tar.gz --exclude='.[^/]*' --directory=../ .
That pattern excludes any name that begins with a dot that is not immediately followed by a slash (so that "./" itself is not excluded).
 
Old 05-25-2014, 06:10 PM   #5
AlanWalker
LQ Newbie
 
Registered: May 2014
Posts: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
That command extracts from a tar archive. It does not create one.
Right (I guess I'd been up awhile by that time). The line should have been
Code:
tar -cvpf ttar.tar.gz --directory=../ --exclude=backups .
Quote:
Originally Posted by rknichols View Post
I'm having trouble figuring out just what you did, but this should extract everything except the dotfiles and directories:
Code:
tar -zxvpf ttar.tar.gz --exclude='.[^/]*' --directory=../ .
That pattern excludes any name that begins with a dot that is not immediately followed by a slash (so that "./" itself is not excluded).
Thank you, I'll try it and get back to you - hopefully with better detail.

Regards,

Last edited by AlanWalker; 05-25-2014 at 06:18 PM.
 
  


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
How to Tar several files and paths and how to restore it? postcd Linux - Newbie 5 03-10-2014 08:22 PM
How to restore files using the restore command ? SKYNAT Linux - Newbie 2 12-28-2007 10:26 PM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
Can tar restore only files newer than already in target directory? lhouk Linux - General 4 08-31-2006 01:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:44 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