Commit 3ff00693 authored by Andrey Filippov's avatar Andrey Filippov

implemented transfer over ssh (10x slower), restored input(), forced python3

parent 5e1a0164
#!/usr/bin/env python
#!/usr/bin/env python3
# Download footage from ssd's raw partition:
# * standalone SSDs connected using a docking station or enclosure or else, raw partition, camera can be powered off
......@@ -72,6 +72,7 @@ parser.add_argument("-bc",type=int,default=512,help="Number of blocks of size [b
parser.add_argument("-fs","--file_start",default="",help=".disk file name with start LBA pointer, will calculate 'skip' value")
parser.add_argument("-fe","--file_end",default="camogm.disk",help=".disk file name with end LBA pointer, default is 'camogm.disk'")
parser.add_argument("dest",help="desitnation directory: /data/footage/test")
parser.add_argument("-l","--lan", action='store_true', help="Transfer data over LAN instead of eSATA")
args = parser.parse_args()
print (args)
......@@ -106,47 +107,69 @@ if len(cams)==0:
pc = x393.PC()
# ssd to camera for all
for cam in cams:
cam['obj'].ssd_to_camera()
# get raw partitions
if (args.lan):
print ("Using data transfer over LAN")
else:
print ("Using data transfer over eSATA, multiplexing camera SSD to eSATA external port")
# ssd to camera for all
for cam in cams:
cam['obj'].ssd_to_camera()
# get raw partitions
for cam in cams:
d = cam['obj'].first_found_raw_partition_name()
d = cam['obj'].first_found_raw_partition_name() # ssh
if d!="undefined":
dirs.append(d)
print(cam['user']+"@"+cam['ip']+": raw partition name: "+d)
else:
cam['disable']=1
print(bcolors.FAIL+cam['user']+"@"+cam['ip']+" : error: already switched or raw partition not found"+bcolors.ENDC)
#raise Exception(cam['user']+"@"+cam['ip']+" : error: already switched or raw partition not found")
# no need
cams[:] = [tmp for tmp in cams if tmp.get('disable')!=1]
# switch ssd to pc for all (not caring which cable is in)
for cam in cams:
cam['obj'].ssd_to_pc()
#raise Exception(cam['user']+"@"+cam['ip']+" : error: already switched or raw partition not found")
# no need
cams[:] = [tmp for tmp in cams if tmp.get('disable')!=1]
if (not args.lan):
# switch ssd to pc for all (not caring which cable is in)
for cam in cams:
cam['obj'].ssd_to_pc()
# download
plist = []
all_downloaded = False
for i in range(len(cams)):
raw_input(bcolors.OKGREEN+"Connect camera (eSATA) to PC (eSATA/SATA). Press Enter to continue..."+bcolors.ENDC)
#for i in range(len(cams)):
for i,cam in enumerate(cams):
# raw_input(bcolors.OKGREEN+"Connect camera (eSATA) to PC (eSATA/SATA). Press Enter to continue..."+bcolors.ENDC)
if (args.lan):
print(bcolors.OKGREEN+"Initiating data transfer over LAN ..."+bcolors.ENDC)
else:
input(bcolors.OKGREEN+"Connect camera (eSATA) to PC (eSATA/SATA). Press Enter to continue..."+bcolors.ENDC)
proceed_to_next = False
t = 0
while not all_downloaded:
plist = pc.list_partitions()
if (args.lan):
plist = cam['obj'].list_partitions_as_host() # Camera partitions, same format as for host (label, path)
#[['NT-1TB_2242_0007988000104', 'sda'], ['NT-1TB_2242_0007988000104-part1', 'sda1'], ['NT-1TB_2242_0007988000104-part2', 'sda2']]
else:
plist = pc.list_partitions() # HOST(!) partitions, such as /dev/sdc1
#[[u'NT-1TB_2242_0007988000104', u'sdc'], [u'NT-1TB_2242_0007988000104-part1', u'sdc1'], [u'NT-1TB_2242_0007988000104-part2', u'sdc2']]
for d in dirs:
for p in plist:
if d==p[0]:
# p[1] == sdb2
# hardcoded /dev/sd?1
if args.n==0:
data_size_blocks = pc.read_camogm_disk_file_blocks("/dev/"+p[1][0:-1]+"1", args.file_end)
data_skip_blocks = pc.read_camogm_disk_file_blocks("/dev/"+p[1][0:-1]+"1", args.file_start)
if (args.lan):
# data_size_blocks = pc.read_camogm_disk_file_blocks_lan(cams[i].ip, p[1][0:-1]+"1", args.file_end)
# data_skip_blocks = pc.read_camogm_disk_file_blocks_lan(cams[i].ip, p[1][0:-1]+"1", args.file_start)
data_size_blocks = cam['obj'].read_camogm_disk_file_blocks(p[1][0:-1]+"1", args.file_end)
data_skip_blocks = cam['obj'].read_camogm_disk_file_blocks(p[1][0:-1]+"1", args.file_start)
#read_camogm_disk_file_blocks
else:
data_size_blocks = pc.read_camogm_disk_file_blocks("/dev/"+p[1][0:-1]+"1", args.file_end)
data_skip_blocks = pc.read_camogm_disk_file_blocks("/dev/"+p[1][0:-1]+"1", args.file_start)
data_size_blocks -= data_skip_blocks # before it included skipped !
else:
data_size_blocks = args.n
......@@ -158,34 +181,31 @@ for i in range(len(cams)):
block_size= 512 # 4096
data_size_gb = (data_size_blocks * block_size) / (1024 * 1024 * 1024)
file_gb = args.bs*args.bc // 1024 # just for compatibility, change to parameter
print("Data size: %d %d-byte blocks (%f GB)"%(data_size_blocks, block_size, data_size_gb))
pc.download_blocks(args.dest, # def download_blocks(self, dest, part, blocks_load, blocks_skip= 0, file_gb=10, chunk_blocks=32768, block_size=512):
"/dev/"+p[1],
blocks_load=data_size_blocks,
blocks_skip= data_skip_blocks,
file_gb=file_gb,
chunk_blocks=chunk_blocks,
block_size=block_size)
'''
data_size = pc.read_camogm_disk_file("/dev/"+p[1][0:-1]+"1")
data_size = round(data_size,2)
# bs is in kB
chunk_size = float(args.bs*args.bc)/1024
n_chunks = int(math.ceil(data_size/chunk_size))
if args.n==0:
args.n = n_chunks - args.skip
print("Data size: "+str(data_size)+" GB")
print(bcolors.BOLDWHITE+"Download size: "+str(args.n)+"x "+str(round(chunk_size,2))+"GB, skipped the first "+str(args.skip)+" chunks"+bcolors.ENDC)
pc.download (args.dest, "/dev/"+p[1], args.bs,args.bc,args.skip,args.n)
'''
# def download(self,dest,part,dl_bs=20,dl_bc=512,dl_skip=0,dl_n=0):
#parser.add_argument("-bs",type=int,default=20,help="block size in MB, default = 20")
#parser.add_argument("-bc",type=int,default=512,help="Number of blocks of size [bs] in a single chunk, default = 512, so the default chunk size is 10GB")
print("Data size: %d %d-byte blocks (%f GB)"%(data_size_blocks, block_size, data_size_gb))
if (args.lan):
print(cam)
pc.download_blocks_lan(
cam,
args.dest,
"/dev/"+p[1],
blocks_load=data_size_blocks,
blocks_skip= data_skip_blocks,
file_gb=file_gb,
chunk_blocks=chunk_blocks,
block_size=block_size)
else:
pc.download_blocks( # after testing use download_blocks_lan (rename/delete download_blocks) with cam=None
args.dest,
"/dev/"+p[1],
blocks_load=data_size_blocks,
blocks_skip= data_skip_blocks,
file_gb=file_gb,
chunk_blocks=chunk_blocks,
block_size=block_size)
dirs.remove(d)
proceed_to_next = True
if len(dirs)!=0:
if len(dirs) != 0:
print("wait for the next ssd")
else:
all_downloaded = True
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment