import math import os import time __author__ = 'sun' source=['/home/sun/byte','/home/sun/bin'] target_dir='/home/sun/backup/' target=target_dir+time.strftime('%Y%m%H%M%S')+'.zip' zip_command="zip -qr '%s' %s" %(target,''.join(source)) if os.system(zip_command)==0: print ('备份成功',target) else: print('备份失败')