LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-17-2021, 12:11 PM   #1
zimon
Member
 
Registered: Sep 2004
Posts: 42

Rep: Reputation: 16
Question Packing and compressing directories to an archive in USB, but writing only N GB at once, then paused?


So if one wants to archive large tree-structure and split it to eg. 60 GB files, one can do:
Code:
tar cJf - /home/user/hugedir | split -b 60G - /mnt/usb64g/hugedir.tar.xz.
But let's assume, the /mnt/usb64g is a NTFS/exFat usb stick of size 64 GB and the /home/user/hugedir is size 256 GB. Let's also assume, there is no enough space in local hard drives to do it there first and then transfer it part by part to 64 GB USB-stick, which is then used to copy file to an another PC.

The purpose is to transfer this hugedir to another machine by the 64 GB USB-stick, part by part. No network. (No fancy USB3.0 USBA - USBA cable, which I Googled could be possible but usually is not.)

Is there any more suitable program but tar+split which would have a pause between writing the chunks? Ideally split-program would have some --pause option, which when have written one chunk, would wait for user keypress before starting to write next one.

tar has -L option, but it not suitable when compression is used.
 
Old 04-17-2021, 10:41 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I don't understand why it has to be compressed.

You could probably do it as follows:
Code:
tar cJf - /home/user/hugedir | dd count=60000 bs=1M of=/mnt/usb64g/hugedir.tar.xz.1
# copy the USB stick to the other machine
tar cJf - /home/user/hugedir | dd skip=60000 count=60000 bs=1M of=/mnt/usb64g/hugedir.tar.xz.2
# copy the USB stick to the other machine
# repeat until done
The skip option skips the first 60000 input blocks.

Then assemble the pieces on the other machine.

Disadvantage: You run the same huge tar command several times. But at least, you get compression.
 
1 members found this post helpful.
Old 04-18-2021, 02:12 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
I would rather try to split the source of that tar into smaller parts (subdirs?), which will fit into that usb stick.
 
Old 04-18-2021, 03:03 AM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,794

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Perhaps a little shell script
Code:
n=1
while
  dd count=60000 bs=1M of=/mnt/usb64g/hugedir.tar.xz.$n <&3
do
  read -p "pause"
  ((n+=1))
done 3< <( tar cJf - /home/user/hugedir )

Last edited by MadeInGermany; 04-18-2021 at 04:34 AM. Reason: The 3 was misplaced
 
1 members found this post helpful.
Old 04-18-2021, 03:18 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
I don't understand why it has to be so complicated. Go buy a 1T external disk - dime-a-dozen these days.
 
Old 04-18-2021, 03:36 AM   #6
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,493

Rep: Reputation: Disabled
That would be my route too, (external disk) - but I'd look at the scripting option in regard to the actual question.
 
Old 04-18-2021, 07:45 PM   #7
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
I have not used it in a long time, but I used to use dar for splitting large backups onto multiple CDs.
 
2 members found this post helpful.
Old 04-21-2021, 09:20 AM   #8
zimon
Member
 
Registered: Sep 2004
Posts: 42

Original Poster
Rep: Reputation: 16
When I was asking the question, it was not possible to get external 1TB disk. And I was wondering this as a challenge and which should not be so difficult to do. But it seems to be.

Both solutions #4 and #7 work if all the pieces of the huge tar file can be stored in the target machine first before extracting. But neither works by using one and only one piece at time.

Solution #4 works, if target machine has free space twice of size hugedir (the splitted tar file is xz-compressed). It needs all pieces of the splitted tar file concatenated in target machine to get extracted.

I tried to pipe it through fifo (mkfifo) but it didn't work either:

Extract1:
Code:
mkfifo /tmp/tarfifo.tar.xz
tar xJf /tmp/tarfifo.tar.xz
It will hang and wait for data from fifo.

Extract2: Concatenate the first transferred piece to fifo:
Code:
cat /mnt/usb64g/hugedir.tar.xz.1 >>/tmp/tarfifo.tar.xz
Fails with error message:
Code:
xz: (stdin): Unexpected end of input
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
Solution #7 using dar worked, but seems like it requires all pieces twice, or at least I couldn't get it work if I removed the transferred chunk every time "dar --extract" already had processed it once.

Create:
Code:
dar --verbose --create /mnt/usb64g/hugedir_xz --compression=xz --execute 'read -p "Wrote %p/%b.dar.%n : Hit RETURN"' --slice 60G --fs-root /home/user/hugedir
Extract:
Code:
dar  --extract /mnt/usb64g/hugedir_xz --execute 'read -p "Wants %p/%b.dar.%n - Hit RETURN"'
When extracting it asks volumes 1, 2, 3, 4, ... but after the last volume/chunk, it wants volume 1 again, and then 2, - wants to read every chunk two times. So here again, if there is not enough space to have the hugedir (256 GB) twice (the second one is xz-compressed though), this solution does not work.

Using tar without compression works:
Create:
Code:
cd /home/user
tar --create --tape-length=60G --file /mnt/usb64g/hugedir.tar hugedir
Prepare volume #2 for ‘hugedir.tar’ and hit return: 
Prepare volume #3 for ‘hugedir.tar’ and hit return: 
Prepare volume #4 for ‘hugedir.tar’ and hit return:
In between here transfer the 64 GB USB flash drive between the source and target machines 2x four times.
Extract:
Code:
cd /home/user2
tar --extract --tape-length=60G --file /mnt/usb64g/hugedir.tar 
Prepare volume #2 for ‘hugedir.tar’ and hit return: 
Prepare volume #3 for ‘hugedir.tar’ and hit return: 
Prepare volume #4 for ‘hugedir.tar’ and hit return:
(Disclaimer: I didn't try this really with 60G "tapes", but with smaller dir and 100k tapes.)

The --tape-length (-L) method with tar does not work with compression though. In fact, not even split having --pause option would work, because tar refuses to extract files from compressed tar file piece by piece.

One solution is to compress the files first in the source machine, transfer with "tar -L", then decompress in the target machine:
Code:
find /home/user/hugedir -type f -exec xz --compress '{}' ';'
Transfer with "tar -L" in pieces and then decompress:
Code:
find /home/user2/hugedir -type f -name "*.xz" -exec xz --decompress '{}' ';'
Compression with tar and using fifo (mkfifo) would work, if somehow fifo would not give EOF (end of file) when the parts are concatenated in in and "tar xJf" reads from there. There should be FIFO, where one must explicitly tell when EOF is outputted. If files are concatenated in it, and read out, it won't tell there is nothing to be read anymore. (I tried Goggling around but found nothing suitable.)

Last edited by zimon; 04-21-2021 at 09:47 AM. Reason: Note about EOF'less FIFO which would work here.
 
Old 04-21-2021, 02:31 PM   #9
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,794

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Code:
cat /mnt/usb64g/hugedir.tar.xz.1 >>/tmp/tarfifo.tar.xz
causes an EOF when the cat command ends.

Using a shell loop again
Code:
while
  read -p "pause" inp
do
  cat /mnt/usb64g/hugedir.tar.xz.1
done >/tmp/tarfifo.tar.xz
Now the output stream (to the fifo) gets an EOF when the loop ends.

With a process substitution the shell handles the fifo (or an equivalent mechanism)
Code:
while
  read -p "pause" inp
do
  cat /mnt/usb64g/hugedir.tar.xz.1 >&3
done 3> >(tar xJf /tmp/tarfifo.tar.xz)
And, if no special file descriptor is used, you can use a pipe
Code:
while
  read -p "pause" inp
do
  cat /mnt/usb64g/hugedir.tar.xz.1
done | tar xJf /tmp/tarfifo.tar.xz
You might want to query the inp variable to gracefully end the loop if a certain value is met.
And you might want to increment the .1 to .2 etc. via a variable.

Last edited by MadeInGermany; 04-21-2021 at 02:40 PM.
 
1 members found this post helpful.
  


Reply

Tags
splitting, tar, transfer



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 the best tool for compressing and un-compressing files? dwhswebhosting Linux - Server 8 03-24-2017 03:30 PM
Can ffmpeg be paused and resume during screen capturing? linuxCode Linux - Software 2 06-14-2013 06:11 PM
Archive Manager not compressing much Chriswaterguy Linux - Software 12 04-21-2008 11:14 PM
tar is not compressing archive file BajaNick Linux - Software 5 06-16-2007 11:21 PM
Knoppix booted once, and only once... abowling Debian 7 02-29-2004 09:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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