`
woshizn
  • 浏览: 209704 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

I want a program which creates a backup of all my important files by Python

阅读更多
#!/usr/bin/python
# Filename: backup_ver4.py
import os
import time
# 1. The files and directories to be backed up are specified in a list.
source = ['"C:\\My Documents"', 'C:\\Code']
# Notice we had to use double quotes inside the string for names with spaces in it.
# 2. The backup must be stored in a main backup directory
target_dir = 'E:\\Backup' # Remember to change this to what you will be using
# 3. The files are backed up into a zip file.
# 4. The current day is the name of the subdirectory in the main directory
today = target_dir + os.sep + time.strftime('%Y%m%d')
# The current time is the name of the zip archive
now = time.strftime('%H%M%S')
# Take a comment from the user to create the name of the zip file
comment = input('Enter a comment --> ')
if len(comment) == 0: # check if a comment was entered
target = today + os.sep + now + '.zip'
else:
target = today + os.sep + now + '_' + \
comment.replace(' ', '_') + '.zip'
# Create the subdirectory if it isn't already there
if not os.path.exists(today):
os.mkdir(today) # make directory
print('Successfully created directory', today)
# 5. We use the zip command to put the files in a zip archive
zip_command = "zip -qr {0} {1}".format(target, ' '.join(source))
# Run the backup
if os.system(zip_command) == 0:
print('Successful backup to', target)
else:
print('Backup FAILED')

Output:
$ python backup_ver4.py
Enter a comment --> added new examples
Successful backup to
E:\Backup\20080702\202836_added_new_examples.zip
$ python backup_ver4.py
Enter a comment -->
Successful backup to E:\Backup\20080702\202839.zip
分享到:
评论

相关推荐

    Python安装包version 3.1.5

    Python 3.x is a new version of the language, which is incompatible with the 2.x line of releases. The language is mostly the same, but many details, especially how built-in objects like dictionaries ...

    Statistical Application Development with R and Python, 2nd-Packt (2017).pdf

    The growth of these two languages and their inter-dependency creates a natural requirement to learn them both. Thus, it was natural where the second edition of my previous title R Statistical ...

    This program takes customers orders by code then creates a b

    This program takes customers orders by code then creates a bill for the purchases. Also can print the bill. All totals are calculated automatically客户购物和打印程序

    VB编程资源大全(英文源码 网络)

    This could be used for what i used it for in the past for a news program<END><br>28 , url.zip Worldwide list of URL extensions by country<END><br>29 , EmailChk.zip This Application checks for ...

    Universal-USB-Installer

    with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute ...

    c或者c++: Structures 结构

    Now write a program that creates a single instance of a structure of type Struct2. Read its member variables from the console one at a time. Create a second instance of Struct2 and copy al the ...

    selenium webdriverAPI-python

    Selenium WebDriver API in Python provides a comprehensive set of methods for automating web browsers. From initializing a WebDriver instance to executing complex JavaScript scripts, these methods ...

    go系统编程(英文版)

    The last part of this chapter implements a utility that creates a copy of all the directories of a directory structure! Chapter 6, File Input and Output, shows you how to read the contents of a file,...

    apng2gif.sf.net.rar

    It disproves the common misconception that Animated PNG files are always too big, as it actually creates APNG files smaller than the original GIFs. Command-line version is very easy to use, and ...

    JSP Simple Examples

    In this example we are making a method named as addNum(int i, int b) which will take two numbers as its parameters and return integer value. Multiple methods Jsp is used mainly for presentation ...

    VclZip pro v3.10.1

    ***IMPORTANT: Please remember do not install these components into a package by the name of either VCLZip or VCLUnZip. You will receive an error if you do. PLEASE TAKE A LOOK AT THE "WHAT's NEW IN ...

    S7A驱动720版本

    - After driver uninstall, not all of the S7A-related registry entries were deleted. Now the registry will be completely cleaned from S7A registry entries after uninstall. - The Netlink module ...

    Python Network Programming Cookbook, 2nd Edition

    Improve your skills to become the next-gen network engineer by learning the various facets of Python programming Book Description Python is an excellent language to use to write code and have fun by ...

    Code implementing A NEW EFFICIENT ELLIPSE DETECTION METHOD 2002

    Algorithm creates list of point pairs, and then checks/scores for candidate ellipse with major axis between a chosen pair of test points, it then estimates minor axis by testing all 3rd points and ...

    Array index out of bound exception

    Write a program that first creates an integer array a[50], and set a[i] = i+3, i=0 to 49. The program next reads in an index k from the user, then calls a method readValue(int [ ] a, int k) that would...

    WizFlow网页编辑

    effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be ...

    hibernate-shards.jar

    effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be ...

    VB编程资源大全(英文源码 数据库)

    <END><br>31 , datsearch.zip Application which searches an Access database for a specified search term entered by the user.<END><br>32 , DBTextGrid.zip This program is the modification of my ...

Global site tag (gtag.js) - Google Analytics