Here is a solution:
printf 'n file-%02d.tar\n' {2..100} |
tar -ML 716800 -cf file-01.tar Documents/ 2>/dev/null
where 100 is a number greater or equal to the number of volumes.
Edit
Setting a big number should not be a problem, though I tend to not take a ridiculous one.
An alternative could be a "next volume" script, that you can set with the -F
option,
tar -ML 716800 -F './myscript file' -cf file.tar Documents/ 2>/dev/null
then in ./myscript
put
#!/bin/bash
prefix="$1"
n=1
while [[ -e "$prefix-$n.tar" ]]; do
((n++))
done
mv "$prefix.tar" "$prefix-$n.tar"
echo "$prefix-$n.tar"
It will be executed at each volume end, and will move file.tar
to the appropriate fileNNN.tar
. For the last volume the script will not be executed, so the last volume name stay file.tar
.
Edit 2
I ended up with the following elaborated solution.
Here are two script, one for the creation and the other for the extraction:
#!/bin/bash
# CREATION SCRIPT
# save on file the initial volume number
echo 1 >number
# multi-volume archive creation
tar -ML 100000 -F './tar-multi-volume-script c file' -cf file.tar Documents2/ 2>&-
# execute the "change-volume" script a last time
./tar-multi-volume-script c file
and
#!/bin/bash
# EXTRACTION SCRIPT
# save on file the initial volume number
echo 1 >number
# execute the "change-volume" script a first time
./tar-multi-volume-script x file
# multi-volume archive extraction
tar -M -F './tar-multi-volume-script x file' -xf file.tar 2>&-
# remove a spurious file
rm file.tar
where ./tar-multi-volume-script
is given by
#!/bin/bash
# TAR INVOKED SCRIPT
mode="$1"
prefix="$2"
n=$(<number)
case $mode in
c) mv "$prefix.tar" "$prefix-$n.tar" ;;
x) cp "$prefix-$n.tar" "$prefix.tar" ;;
esac
echo $((n+1)) >number
Obviously you have to change many bits here and there to adapt to your situation and to be sure it would work in cron
, that is always a little challenge.
You can add a rate limiting tool to your pipeline.
For example there is pv
which has a rate-limiting option:
-L RATE, --rate-limit RATE
Limit the transfer to a maximum of RATE bytes per second. A suffix of "k", "m", "g", or "t" can be added to denote kilobytes (*1024), megabytes, and so on
An alternative is the tool buffer
which has:
-u microseconds
After every write pause for this many microseconds. Defaults to zero. (Surprisingly a small sleep, 100 usecs, after each write can greatly
enhance throughput on some drives.)
Best Answer
You can run your tar command using
ionice
. Like this:This will let the
tar
process only do I/O when there is no other process waiting for I/O.In Debian the
ionice
utility is in the packageutil-linux
, so you you may need to install that first.Like with the normal (cpu)
nice
utility, the I/O scheduler class of a process is inherited by its child processes. When I'm planning to do resource-heavy stuff, I do not want users have their I/O slowed down because of it. I often start my shell this way:Then everything I do from that shell will be very, very nice :)