LinuxQuestions.org
Review your favorite Linux distribution.
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 04-14-2016, 01:59 PM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
How to tgz all folders individually


I have a /data folder. Below that are 65 folders (that contain subfolders), is there a slick command I could run to create 65 foldername.tgz files so i have a tgz backup of each directory and all it's subcontents individually? I'd like to avoid typing 65 individual commands

Last edited by anon091; 04-14-2016 at 02:00 PM. Reason: number typo
 
Old 04-14-2016, 02:50 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Yes.

Oh, you want the command...

First set your working directory to the directory where the directories you want backed up.

find * -maxdepth 0 -type d -exec tar -czf '{}'.tgz '{}' ';'

should do it. The result should be 65 tar files. If you want a brief log of the activity, you can add "-print" between the the "-type d" and the "-exec".

There is a variant that does things in parallel (though it might not be good for 65...):
Code:
find * -maxdepth 0 -type d -print | while read V; do
 tar -czf $V.tgz $V &
done
The warning is that this spawns of a new process for each tar command in background, giving you 65 background processes running tar.

It can be faster as overlapped read/writes get done in parallel, but can overload a single processor.

In both cases, if you want the target tgz file somewhere other than in the working directory, include a path in front of the tgz file.

Last edited by jpollard; 04-14-2016 at 02:59 PM.
 
1 members found this post helpful.
Old 04-14-2016, 03:48 PM   #3
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Thanks. I think the parallel one may bring the server to it's knees haha, they're all pretty big directories each.
 
Old 04-14-2016, 04:33 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Possibly. I can see doing two to maybe four at a time without a problem, but coding up the waits is a bit of a pain.

Using "make" is an alternative, but creating the Makefile might be tricky.... (it has a nice -j option to limit the number of parallel actions).

Last edited by jpollard; 04-14-2016 at 04:35 PM.
 
Old 04-14-2016, 04:34 PM   #5
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Understood. Thanks again for the help. Going to try it out tonight when the load on the server is lighter.
 
Old 04-14-2016, 04:49 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by rjo98 View Post
Understood. Thanks again for the help. Going to try it out tonight when the load on the server is lighter.
Save yourself! Run it in screen.
 
1 members found this post helpful.
Old 04-14-2016, 04:53 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by Habitual View Post
Save yourself! Run it in screen.
Or just redirect both stdout/sterr into a log file and run it in the background.

Screen is nice, but there are times it doesn't do well... and losing output is one of the things that can happen.
 
1 members found this post helpful.
Old 04-15-2016, 07:35 AM   #8
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
ha, thanks guys.
 
  


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
sorting columns individually a_bahreini Linux - Newbie 18 03-26-2014 08:05 PM
How to tar all subdirectories individually? Mountain Linux - Software 9 04-26-2009 11:41 PM
a tgz that doesn't end in tgz flebber VectorLinux 3 05-03-2006 05:31 AM
tgz file doesn't end in .tgz? detpenguin Slackware 4 05-15-2004 07:13 PM
X Sever crash after xset.tgz & vg16.tgz install lachlan Slackware 0 08-13-2003 02:48 AM

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

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