copy sparse files
I've a big sparse file ( about 100 GB that only 1 GB of it is used and it's .raw file )
I want to copy this file faster than normal copy with cp command, Any one familiar with this concept? |
My first reaction: Why would you want or need such a file?
Regardless, I'd assume that any action to compress the file before copying would take more time than simply copying it. But, if you need to copy it many times, then just compress it. You could also try "dd", but I have no idea if it would be faster. Maybe try it on a smaller file. |
Hi,
Quote:
:hattip: |
Quote:
Do you need the bloat - the extra 99 Gig? If so, and you have another 30 or 40 gig for a temporary file, why not 'gzip sparse_file'. If you don't need the crap, give details on the stuff you want, and the stuff you want to leave behind. |
use bzip2 -9 filename. This has maximum compression.
Although, it may take considerable time compressing/uncompressing the file. I would suggest you to bzip2 it, if in case you need to copy it again and again. |
xz takes very, very, very long to compress, but it produces much smaller files and, ironically, decompresses really fast!
|
I've many of these files, and it's every day job of mine,
the most important factor for me is time, I want to do it faster than cp command |
You probably can't.
I just ran some tests, and "cp" appears to recognise sparse (input) files o.k. However strace shows it issuing a read every 32k. There is also a corresponding seek on the output fd. All that takes time, even if the file is completely empty (as in my test). Update: got me wondering now - how much benefit is there in that. A file of the same size full of random data issues the same number of reads, and issues writes in place of seeks. Takes much longer of course, but if a sparse file is (actually) zero bytes, why all the reads ... I see if I can chase this up tomorrow. |
Just for the post, try a race. I would suggest gzip -1, as you are not particularly pressed for space. You could also do a cron job to have the zipping done when you are at home :-D
|
rsync's --sparse option makes it "handle sparse files efficiently" (so says the man page).
|
I was thinking about this on the ride home. Looking at the manpage confirms that "cp" is only looking to see if a sparse output allocation is required.
I'll check rsync tomorrow. |
Hi,
Quote:
:hattip: |
O.K., some more testing showed the above "cost" for cp is all set-up of a new file. Repeated copies into the (pre-allocated) destination file showed minimal reads and writes.
Far better than rsync (-b -S) in fact. Both cp and rsync created a sparse output, but rsync continued to read and write the entire file when only a couple of sectors out of 1Gig had non-zero data. cp was much more efficient. Similar results for 5 Meg input. My test, my data, my machine, YMMV, <blah>, <blah>, <blah> ... |
Quote:
|
Yes - especially if you can re-use the output files each day (after the first obviously). That is, don't delete the (output) files each day, over-write them.
The "-b" on the rsync was *bad* - but even with "-t" (or -a), "cp" was still marginally faster. Which surprised me I must admit. |
All times are GMT -5. The time now is 08:36 AM. |