首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python简明教程第十章关于备份文件的程序在linux终端运行不成功!(来者有分)解决办法

2012-02-17 
python简明教程第十章关于备份文件的程序在linux终端运行不成功!(来者有分)原文程序 如下:import osimport

python简明教程第十章关于备份文件的程序在linux终端运行不成功!(来者有分)
原文程序 如下:
import os
import time
# 1. The files and directories to be backed up are specified in a list.
source = ['/home/swaroop/byte', '/home/swaroop/bin']
# If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something 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 using
# 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'
# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
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'

下面是我自己的:
import os
import time

source=['/home/guanyu/python/Demo','/home/guanyu/python/Shell']
target_dir='/home/guanyu/backup/'
target=target_dir+time.strftime('%Y%m%d%H%M%S')+'.zip'
zip_command="zip -qr '%s'%s"%(target,' '.join(source))

if os.system(zip_command)==0:
  print 'Successful backup to',target
else:
  print 'Backup FAILED'

每次运行后都会提示:
zip error: Nothing to do! (try: zip -qr /home/guanyu/backup/20110715104505.zip/home/guanyu/python/Demo . -i /home/guanyu/python/Shell)

怎么改?运行成功后,他是把'/home/guanyu/python/Demo'变成zip,命名为/home/guanyu/backup/20110715104505.zip并保存在/home/guanyu/python/Shell中吗?

[解决办法]

探讨
zip -qr /home/guanyu/backup/20110715104505.zip/home/guanyu/python/Demo . -i /home/guanyu/python/Shell

热点排行