def archive_dir(source, arcname, target, arc_time):
# Set the filename and destination.
arcname = str(arc_time)+'_'+arcname+'.zip' # Archive filename
target = str(target+'/'+arcname) # Path to storage...
dirs = [str(source)] # Set initial "root" directories to pop.
zipObj = zipfile.ZipFile(target,'w',zipfile.ZIP_DEFLATED)
try:
while dirs:
# Loop through and get all sub dirs and files.
dir_list=dirs.pop(0) # pop next dir.
try:
for items in os.listdir(dir_list+'/'):
if os.path.isdir(dir_list+'/'+items):
# Collect sub dirs for pop.
dirs+=[dir_list+'/'+items]
elif os.path.isfile(dir_list+'/'+items):
# Ignor the archive file if in the dir structure.
if items.lower() == arcname: continue
if items.lower()[:3] == 'ini': continue #task directory filter.
# Write to the zip.
zipObj.write(str(dir_list+'/'+items),None,None)
except:
pass # Ignor non-accessable directories!
zipObj.close()
return 1 # Success...
except Exception, error:
return error # Backup failed...
#//////////////////////////////////////////////////////>
# CONFIGURATION AND PATH SETUPS
#//////////////////////////////////////////////////////>
# SPECIFY SOURCE PATHS; add as many as you like.
# Don't forget to add these to the SOURCE_PATH list below.
评论列表
文章目录