I have used the below code, it can compress folders. But when I uncompress folders, it will throw an error. I think there is something wrong with my code. Any advice is welcome.
def compress_index():
"将/var/solr/core0/data索引目录进行打包压缩至同目录下,以该日时间命名的data.tar.gz.20101013形式的压缩包"
parentdirs,folder=os.path.split(g_index_path)
tar_filename=os.path.join(parentdirs,folder+".tar.gz.%s"%datetime.datetime.now().strftime("%Y%m%d"))
if os.path.exists(tar_filename):
print "已经存在同名压缩文件,删除再压缩"
delete(tar_filename)
cmd="tar -zcvf %s %s"%(tar_filename,g_index_path)
print cmd
subprocess.call(cmd.split())
print "将索引%s压缩打包到%s完成"%(g_index_path,tar_filename)