工作,学习,生活,这里将会有一些记录. 备用域名:http://meisw.wdlinux.cn 注册 | 登陆

python

source = ['/home/swaroop/byte', '/home/swaroop/bin']
# If you are using Windows, use source = [r'C:\Documents',r'D:\Work'] or somethi
ng like that
# 2. The backup must be stored in a main backup directory
target_dir = '/mnt/e/backup/' # Remember to change this to what you will be usin
g
# 3. The files are backed up into a zip file.
# 4. The name of the zip archive is the current date and time
target   =   target_dir   +  time.strftime('%Y%m%d%H%M%S') + '.zip'


if not os.path.exists(today): 
   os.mkdir(today) # make directory 
   print 'Successfully created directory', today


comment = raw_input('Enter a comment --> ')
if len(comment) == 0: # check if a comment was entered
   target = today + os.sep + now + '.zip'
else:
   target = today + os.sep + now + '_' + \
      comment.replace(' ', '_') + '.zip'

 

zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
# Run the backup
if os.system(zip_command) == 0:
  print 'Successful backup to', target
else:
  print 'Backup FAILED'

 

 

« 上一篇 | 下一篇 »

Trackbacks

点击获得Trackback地址,Encode: UTF-8

发表评论

评论内容 (必填):