Python to build a simple backup script

Source: Internet
Author: User
Tags call back

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.