Question

I have an external hard-drive that I suspect is on its way out. At the minute, I can transfer files from it, but only for a while. Unfortunately, I have one single file that's >50GB in size. My solution to this is to use rsync to transfer this one particular file a bit at a time, leave the drive to rest (switch it off), and resume a little while later.

I'm using rsync --partial --progress --inplace --append -a /Volumes/Backup\ Drive/chris/Desktop/Recording\ Sessions/S1/Session\ 1/untitled ~/Desktop/temp to transfer it. (The file is in the untitled folder, which I'm moving into the temp folder) However, after having stopped it and resumed it, it seems to be over-writing the previous attempt at the file, meaning I don't really get any further.

Is there something I'm missing? :X

Thankyou ^_^

EDIT: Still don't know :\

Was it helpful?

Solution

Well, since this is a programming site, here's a program to do it. I tested it on OS X, but you should definitely test it on some small files first to make sure it does what you want:

#!/usr/bin/env python                                                                                                   

import os
import sys

source = sys.argv[1]
target = sys.argv[2]
begin = int(sys.argv[3])
end = int(sys.argv[4])

mode = 'r+b' if os.path.exists(target) else 'w+b'

with open(source, 'rb') as source_file, open(target, mode) as target_file:
    source_file.seek(begin)
    target_file.seek(begin)
    buffer = source_file.read(end - begin)
    target_file.write(buffer)

You run this with four arguments: the source file, the destination, and two numbers. The first number is the byte count to start copying from (so on the first run you'd use 0). The second number is the byte count to copy until (not including). So on subsequent runs you'd always use the previous fourth argument as the new third argument (new begin equals old end). And just go on like that until it's done, using whatever sizes you like along the way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top