Many books talk about Python backup in linux, and you can run the backup function on xp. The code is almost the same, that is, it is different when packaging. Winrar is also used, and the same applies to other compressed files.
First, we need to add the winrar path to the path, which is valid only after the host is restarted.
Note: After you add the winrar path to the path, you must restart it. Otherwise, the path setting will not take effect and the package will fail!
The command used here is: winrar a xxx.zip xxxx
Xxx is any character
The instance code is as follows:
# Backup script used for backup # Filename: backup_ver1.py import OS import time import sys # source file path sourc = ['G: // test // test.txt '] # target_dir = 'G: // '# Name of the backup file target = target_dir + time.strftime('policyuncm=d?h=m=s'{}'.rar' # zip_command = "zip-qr '% s' % s" % (target ,''. join (sourc) # zip_command = "winrar a/" % s/"% s" % (target ,''. join (sourc) zip_command = "winrar a % s" % (target ,''. join (sourc) print zip_com Mand if OS. system (zip_command) = 0: print 'Package successful! '+ Target else: print' Packaging failed!