#Filename:backup_ver1
import os
import time
#1 Using list to specify the files and directory to be backed up
source = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\Dr Py\Final_Py'
#2 define backup directory
destination = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\PyDevResourse'
#3 Setting the backup name
targetBackup = destination + time.strftime('%Y%m%d%H%M%S') + '.rar'
rar_command = "rar.exe a -ag '%s' %s" % (targetBackup, ''.join(source))
##i am sure i am doing something wrong here - rar command please let me know
if os.system(rar_command) == 0:
print 'Successful backup to', targetBackup
else:
print 'Backup FAILED'
O/P:- Backup FAILED
WinRAR是下添加到环境变量PATH和CLASSPATH以及 - 任何人与备份目录的建议是非常值得欢迎Python脚本备份目录
好的,我这样做(导入tarfile模块),它运行安静 - 我没有给任何消息,因为没有任何东西添加产生一条消息 - 我检查了位置destination = os.path.join(root,“文档和设置“,”rgolwalkar“,”桌面“,”桌面“,”PyDevResourse“)但没有找到备份。第二,如果我添加: - 如果os.system(tar)== 0:打印'成功备份到',targetBackup其他:打印'备份失败' - 如果os.system(tar)== 1出现错误:TypeError:system()参数1必须是字符串,而不是TarFile – rgolwalkar
只是好奇,为什么你使用rar而不是跨平台的东西,比如zip,它被内置到python中? –