?
Solved

Create Tar file in unix and split it to smaller segments

Posted on 2014-09-04
6
Medium Priority
?
1,473 Views
Last Modified: 2014-09-04
I need to split a large tar file for backup purposes on a unix system. I need to tar the /u/appl directory and then split into chunks less the 2gb in size. The following command is what I'm using now, but I get an error "Split: cannot open input".

tar cvf - /u/appl | split -b 1500m /u/backup/appl.backup.tar.gz

I'm sure there's a syntax error, as I can run the tar command by itself with no issue. I've tried to resolve but haven't been able to.
0
Comment
Question by:sdholden28
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 23

Assisted Solution

by:nemws1
nemws1 earned 1000 total points
ID: 40303517
You need to provide an input file parameter to split.  In this case, you want STDIN, so you just need a hyphen:

 tar cvf - /u/appl | split -b 1500m - /u/backup/appl.backup.tar.gz

Open in new window

0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1000 total points
ID: 40303534
You must tell split which input to read. In your case it's stdin, expressed as "-"

tar czvf - /u/appl | split -d -b 1500m - /u/backup/appl.backup.tar.gz

"-d" tells split to use numeric suffixes. Use the "-z" flag of tar to compress.

Please be aware that you must concatenate the single input files before feeding them to tar for extracting!

cat /u/backup/appl.backup.tar.gz* | tar -xzvf -

tar is also able to create multi-volume archives.

If you know roundabout how big your input data will be you can do

tar -c -M -L 1536000 --file =/u/backup/appl.backup.tar1 --file =/u/backup/appl.backup.tar2 --file= /u/backup/appl.backup.tar3 --file =/u/backup/appl.backup.tar4

Note: You cannot use compression when the "-L" flag is in effect.

You can repeat the "--file" parameter as often as needed. "-L" specifies the chunk size in K.

You can also specify just one filename. tar will prompt you for the name of the next file once the amount of data specified by "-L" (in K) has been archived.. Answer the question "Prepare volume #n for 'archive' and hit return:" with "n new_file_name".

Finally, you can use a "new volume" script to get rid of the prompts. Here is how it works: http://www.gnu.org/software/tar/manual/tar.html#Using-Multiple-Tapes
0
 

Author Comment

by:sdholden28
ID: 40303985
does stdin use temp space on /dev/root? That looks to be the case as I'm running into a space issue in my test environment. Can I direct the temp storage to /u somehow?
0
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40303987
stdin/stdout  do not use intermediate (temporary) disk space.
0
 
LVL 23

Assisted Solution

by:nemws1
nemws1 earned 1000 total points
ID: 40304102
split *might* be using temp space (I kinda doubt it, though).

Maybe just try this (make sure both tar and split use the temporary TMP location).

mkdir /u/tmp
chmod 700 /u/tmp
TMP=/u/tmp tar cvf - /u/appl | TMP=/u/tmp split -b 1500m - /u/backup/appl.backup.tar.gz

Open in new window

0
 

Author Closing Comment

by:sdholden28
ID: 40304890
Thanks gentlemen, got it sorted. Could've solved my problem with the info from nemws1 alone, but I greatly appreciate the extra info from woolmilkporc and I used it to implement a better solution, so I split the points. Thanks again.
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question