代码: 全选
import os
import time
# 1. The files and directories to be backed up are specified in a list.
source = [r'D:\python', r'D:\python2']
# If you are using linux, use source = ['/home/python', '/home/python2] or something like that
# 2. The backup must be stored in a main backup directory
target_dir = r'D:\pybackup'
# 3. The files are backed up into a rar file.
# 4. The name of the rar archive is the current date and time
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.rar'
# 5. We use the rar command to put the files in a rar archive
rar_command = "winrar '%s' '%s'"(target, ' '.join (source))
# 6. Run the backup
if os.system(rar_command) == 0:
print('successful backup to', target)
else:
print('backup failed')
以下是报错信息:
代码: 全选
Traceback (most recent call last):
File "D:\python\backup_ver1.py", line 19, in <module>
rar_command = "winrar '%s' '%s'"(target, ' '.join (source))
TypeError: 'str' object is not callable