Python backup program code implementation, python backup program code
A Python backup program
This is a backup script. Change the path.
This is a backup script, which is divided into directories based on the current date and uses the time as the file name. You can add remarks to the file name.
Use zip as the compression mode. You can change it if you have special requirements.
Instance code:
#! /Usr/bin/python # coding = UTF-8 # This is a backup script, which divides directories by the current date and uses time as the file name. You can add remarks to the file name. # Use zip as the compression mode. You can change it if you have special requirements. import osimport time source = ['/home/leeicoding/workspace/j2ee ', '/home/leeicoding/workspace/python'] target_dir ='/home/leeicoding/Bak' # obtain the system time today = target_dir + time. strftime ('% Y % m % D') now = time. strftime ('% H % M % s') # Enter comment = raw_input ('enter remarks:') if len (comment) = 0: print ('no note') target = today + OS. sep + now + '.zip 'else: target = today + OS. sep + now + comment. replace ('', '_') + '.zip 'if not OS. path. exists (today): OS. mkdir (today) print ('create directory '+ today + 'successfully ') # BACKUP command # q silent mode r recursive directory zip_command = 'zip-qr "% s" % s' % (target ,''. join (source) if OS. system (zip_command) = 0: print ('backup successful, stored in: '+ target)
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!