1 #!/usr/bin/python
2 import os
3 import time
4 source=['/home/wanghao/byte','/home/wanghao/bin']
5 target_dir = '/home/wanghao/'
6 today = target_dir + time.strftime('%Y%m%d')
7 now = time.strftime('%H%M%S')
8 comment = raw_input('Enter acomment-->')
9 if len(comment) == 0:
10
target=today + so.sep + now + '.tar.gz'
11 else:
12
target = today + os.sep + now + '_' + comment.replace('','') + '.tar
.gz'
13 if not os.path.exists(today):
14
os.mkdir(today)
15
print 'Sucessful created directory',today
16 tar_command = "tar -zcvf '%s' %s" % (target,' '.join(source))
17 if os.system(tar_command)==0:
18
print 'Successful backup to',target
19 else:
20
print 'Backup FAILED'
文件夹为当前日期,文件名为当前日期