前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python 学习笔记: 备份工具

Python 学习笔记: 备份工具

作者头像
用户3135539
发布2018-09-12 11:02:18
3890
发布2018-09-12 11:02:18
举报
文章被收录于专栏:
代码语言:javascript
复制
1 #!/usr/bin/python
 2 #filename:backup_ver3.py
 3 import os
 4 import time
 5 
 6 source=['/media/Work/WorkSpaces/gooapp','/media/Work/WorkSpaces/RsaTool']
 7 target_dir='/media/Work/backup/'
 8 today = target_dir + time.strftime('%Y%m%d')
 9 now = time.strftime('%H%M%S')
10 
11 comment = raw_input('Enter a comment:')
12 if len(comment) == 0:
13     target = today + os.sep + now + '.tar'
14 else:
15     target = today + os.sep + now + '_' + comment.replace(' ','_') + '.tar'
16             
17 if not os.path.exists(today):
18     os.mkdir(today)
19     print 'Sucessfully created directory',today
20     
21 tar_command = 'tar -cvzf %s %s' % (target, ' '.join(source)) 
22 
23 if os.system(tar_command) == 0:
24     print 'Successful backup to',target
25 else:
26     print 'Backup FAILED'
27
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2009-01-08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档