python备份脚本
2011-09-18 20:18
204 查看
<bk1>引用os,time,sys模块,join()函数
<bk2>判断目录是否存在
<bk3>os.sep的应用
本文出自 “Larry学习之路” 博客,请务必保留此出处http://5iqiong.blog.51cto.com/2999926/667898
#!/usr/bin/python #2011/09/17 by larry import time,os,sys start_data=['/home/tech1/lianghq','/home/tech1/bak1/'] source_data=' '.join(start_data) T=time.strftime('%F-%H%M') bak_data='/tmp/liang/%s' % (T) bak_command='tar czvf %s.tgz %s' % (bak_data,source_data) print bak_command if os.system(bak_command)==0: print 'The bak data,is successfull',bak_data else: print "Backup failed."
<bk2>判断目录是否存在
#!/usr/bin/python #2011/09/18 by larry import time,os,sys Tdir=time.strftime('%Y%m%d') dir='/tmp/lianghq/%s' % (Tdir) if not os.path.exists(dir): os.mkdir(dir) print "It's successful to created directory",dir start_data=['/home/tech1/lianghq','/home/tech1/bak1/'] source_data=' '.join(start_data) T=time.strftime('%F-%H%M') bak_data='/tmp/lianghq/%s/%s' % (Tdir,T) bak_command='tar czvf %s.tgz %s' % (bak_data,source_data) if os.system(bak_command)==0: print 'The bak data,is successfull',bak_data else: print "Backup failed."
<bk3>os.sep的应用
#!/usr/bin/python import time,os,sys dir1='/tmp/lianghq' dir=dir1+os.sep+time.strftime('%Y%m%d') if not os.path.exists(dir): os.mkdir(dir) print "It's successful to created directory",dir start_data=['/home/tech1/lianghq','/home/tech1/bak1/'] source_data=' '.join(start_data) bak_data=dir+os.sep+time.strftime('%Y%m%d-%H%M%S') bak_command='tar czvf %s.tgz %s' % (bak_data,source_data) if os.system(bak_command)==0: print 'The bak data,is successfull',bak_data else: print "Backup failed."
本文出自 “Larry学习之路” 博客,请务必保留此出处http://5iqiong.blog.51cto.com/2999926/667898
相关文章推荐
- python备份数据脚本
- 用python备份mysql数据库的脚本
- python备份脚本
- python2备份交换机配置脚本
- python文件备份脚本
- python备份目录脚本
- python构建一个简单的备份脚本
- python脚本按表备份MySQL数据库
- 编写第一个python 脚本(重要文件创建备份)
- python常用的备份脚本
- 实验室的一段Python脚本 “备份文件操作”
- windows和linux下的python备份脚本
- (windows)python脚本:自动备份并压缩文件,同时删除过期文件
- python备份文件以及mysql数据库的脚本代码
- Python 数据库备份脚本(邮件通知+日志记录)
- python 备份脚本
- 【python】脚本001-文件备份(模板)
- Python备份思科设备的脚本
- 用python编写脚本实现备份文件
- python备份脚本解析