Writing ideas:
1. Create an empty list, write the data that needs to be backed up to the list, and make it easy to call back.
2, the establishment of backup storage directory.
3. Call the OS module to read the data from the list and then call the tar command to back it up.
#!/usr/bin/python
#luohui
Import time
Import Sys
Import OS
SOURCE =[]
Backup_dir= '/backup '
Import OS
SOURCE =[]
Backup_dir= '/backup '
Today = Backup_dir + os.sep + time.strftime ('%y%m%d ')
Dir = today + os.sep +time.strftime ('%h%m%s ') + '. tar.gz '
For I in SYS.ARGV:
Print I
if i = = Sys.argv[0]:
Continue
Source.append (i)
#print Source
#print Source.index (i)
List=source[source.index (i)]
#print Len (source)
Print Dir
print '-----------------------'
If Len (source) = = 0:
Print "Please input the file or Directories,like
Python backup1.py/etc/etc/fstab "'
Exit ()
Else
print ' Please wait: '
Print Source
Os.system ("mkdir-p%s"% (today))
Os.system ("tar-zcvf%s%s"% (dir, list))
Here, a simple backup has been completed. It's easy to optimize later.
This article is from the "Little Luo" blog, please be sure to keep this source http://xiaoluoge.blog.51cto.com/9141967/1590756
Python to build a simple backup script