这应该工作:
import osimport tarfilehome = '/home/'backup_dir = '/backup/'home_dirs = [ name for name in os.listdir(home) if os.path.isdir(os.path.join(home, name)) ]for directory in home_dirs: full_dir = os.path.join(home, directory) tar = tarfile.open(os.path.join(backup_dir, directory+'.tar.gz'), 'w:gz') tar.add(full_dir) tar.close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)