first release. readme will follow up
This commit is contained in:
89
swift_delete_orphan_segments.py
Normal file
89
swift_delete_orphan_segments.py
Normal file
@@ -0,0 +1,89 @@
|
||||
__author__ = 'xgiovio'
|
||||
|
||||
|
||||
|
||||
import authentication, utility
|
||||
|
||||
def launch(swift_container,delete,fail_tries):
|
||||
print ("Swift container " + swift_container)
|
||||
print("___________")
|
||||
|
||||
swift_conn = authentication.set_authentication ()
|
||||
|
||||
listfoldermanifest=[]
|
||||
#all files on the container
|
||||
swift_conn,container_objects_raw = utility.get_list(fail_tries,swift_conn,swift_container,"")
|
||||
#get dict name:manifesturl only for large files
|
||||
byte0manifest,swift_conn,container_objects_manifest = utility.list_compute_manifest (fail_tries,container_objects_raw,swift_conn,swift_container,"")
|
||||
for name,manifest in container_objects_manifest.items():
|
||||
listfoldermanifest.append(manifest)
|
||||
'''
|
||||
for o in listfoldermanifest:
|
||||
print(o)
|
||||
'''
|
||||
#_____________________________________________________________________________________________________________________
|
||||
#______________________________Folders with segments
|
||||
listfoldersegmentsprefix = []
|
||||
|
||||
#______________________________Folders with segments : container: swift_container +"_segments"
|
||||
|
||||
#all files on container_segments -> they are only segments
|
||||
swift_conn,container_segments_objects_raw = utility.get_list(fail_tries,swift_conn,swift_container +"_segments","")
|
||||
#get dict name:size
|
||||
container_segments_objects = utility.list (container_segments_objects_raw,"")
|
||||
#get list only with folders path name from segments
|
||||
listfolder = []
|
||||
for name in container_segments_objects.keys():
|
||||
if utility.folder_from_path(name,"/") not in listfolder :
|
||||
listfolder.append(utility.folder_from_path(name,"/"))
|
||||
for o in listfolder:
|
||||
listfoldersegmentsprefix.append(swift_container +"_segments/" + o)
|
||||
|
||||
#______________________________Folders with segments : container: swift_container path: @SynologyCloudSync/
|
||||
#all files @SynologyCloudSync/ on container -> they are only segments
|
||||
#get dict name:size
|
||||
container_segments_objects = utility.filter_list_begin(container_objects_raw,"@SynologyCloudSync/","")
|
||||
#get list only with folders path name from segments
|
||||
listfolder = []
|
||||
for name in container_segments_objects.keys():
|
||||
if utility.folder_from_path(name,"/") not in listfolder :
|
||||
listfolder.append(utility.folder_from_path(name,"/"))
|
||||
for o in listfolder:
|
||||
listfoldersegmentsprefix.append(swift_container +"/" + o)
|
||||
|
||||
|
||||
#______________________________Folders with segments "!CB_"
|
||||
#all files !CB_ of CloudBerry on container -> they are only segments
|
||||
#get dict name:size
|
||||
container_segments_objects = utility.search_list(container_objects_raw,"!CB_","")
|
||||
#get list only with folders path name from segments
|
||||
listfolder = []
|
||||
for name in container_segments_objects.keys():
|
||||
if utility.folder_from_path(name,"_") not in listfolder :
|
||||
listfolder.append(utility.folder_from_path(name,"_"))
|
||||
for o in listfolder:
|
||||
listfoldersegmentsprefix.append(swift_container +"/" + o)
|
||||
|
||||
'''
|
||||
for o in listfoldersegmentsprefix:
|
||||
print(o)
|
||||
'''
|
||||
#_____________________________________________________________________________________________________________________
|
||||
|
||||
segments_to_delete = []
|
||||
segments_not_listed = []
|
||||
for manifesturlsegments in listfoldersegmentsprefix :
|
||||
if manifesturlsegments not in listfoldermanifest:
|
||||
segments_to_delete.append(manifesturlsegments)
|
||||
|
||||
for manifest in segments_to_delete:
|
||||
print("Segments folder to delete: " + manifest)
|
||||
|
||||
for manifesturl in listfoldermanifest :
|
||||
if manifesturl not in listfoldersegmentsprefix:
|
||||
segments_not_listed.append(manifesturl)
|
||||
|
||||
for manifest in segments_not_listed:
|
||||
print("Segments not present in given segments list : " + manifest)
|
||||
|
||||
swift_conn.close()
|
||||
Reference in New Issue
Block a user