As Bichoy indicated you can use the find
command to find files with a specific access, create and modification time. However -mtime takes an offset in 24 hour increments and is not always convenient to calculate unless you want something from a specific amount of numbers of 'days' ago. You will need to combine that with -daystart
to 'round' that to the beginning of the day.
I think more convenient in your case, is the -newermt option which takes a datestring (and not the name of a reference file like most -newerXY versions)
Combine that with find
's -print0
option to handle files with spaces in the name and optionally -type f
not to get any directories in the period you are interested in:
find /var/lib/edumate/backup/archive_logs/db2inst1/SAAS \
-newermt 20130310 -not -newermt 20130314 -type f -print0 \
| xargs -0 tar -cvzf /tmp/saas_archive_logs.tar.gz
There is one big problem with that: in case the number of files found becomes to long, xargs
will invoke its command (in this case tar
) multiple times as xargs
needs to fit the arguments on the commandline which is not infinite.
To circumvent that I always use cpio
, which reads filenames from stdin. With the --format=ustar
parameter to get a POSIX tar file, and in your case you would need to pipe the output through gzip
to get the desired result:
find /var/lib/edumate/backup/archive_logs/db2inst1/SAAS \
-newermt 20130310 -not -newermt 20130314 -type f -print0 \
| cpio --create --null --format=ustar \
| gzip > /tmp/saas_archive_logs.tar.gz
You can use tar
, with these options:
--new-volume-script=COMMAND
--tape-length=N
At the end of each volume it will call your script, that will have some environment variables to know which volume has just been processed. Check the manual page for the full list, but at least the variable TAR_VOLUME
is pretty useful, in case you have to rename the output file, or keep somehow track of the current volume:
TAR_VOLUME
Ordinal number of the volume tar
is processing (set if
reading a multi-volume archive).
If the script returns 0, tar
will continue, otherwise it will stop.
For example, this will create each volume, with a maximum size of 20 M, calling your script each time the limit is reached:
tar cvf /tmp/volume.tar /path/to/files/ --new-volume-script=/path/to/myscript.sh --tape-length=20M
The script can be a simple echo "Next volume";read
or you could even do the transfer from it (renaming the volume, because once you exit /tmp/volume.tar
will be overwritten).
On the other side, be sure to use the flag --multi-volume
. If you don't, tar will stop with the errors (I leave it in case somebody searches for the error):
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
tar xvf /path/to/transferred.volume --multi-volume
Prepare volume #2 for /path/to/transferred.volume and hit return:
tar
will prompt you for the new volume. Once you press Enter, /path/to/transferred.volume
will be opened again, and so on.
Best Answer
If the recipient has
split
, then you can do: