使用python作一个简单的备份
-
#!/usr/bin/env python
-
# Filename: backup_ver1.py
-
-
import os
-
import time
-
-
# 1. 备份的目录及文件列表
-
source=['./src/1.txt','./src/2.txt']
-
# If you are using Windows, use source=[r'C:\Documents',r'D:\Work'] or something like that
-
-
# 2. 备份目标目录
-
target_dir='./bak/' #Remember to change this to what you will be using
-
-
# 3. The files are backed up into a zip file
-
# 4. The name of the zip archive is the current date and time
-
target=target_dir+time.strftime('%Y%m%d%H%M%S')+'.zip'
-
-
# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
-
zip_command="zip -qr '%s' %s" %(target,' '.join(source))
-
-
# Run the backup
-
if os.system(zip_command)==0:
-
print ('Successful backup to', target)
-
else:
-
print ('Backup FAILED')
-
结果:
-
>>> ================================ RESTART ================================
>>>
Successful backup to ./bak/20130926225932.zip
>>>
python---类
使用class name:定义一个类
类方法 比普通函数多一个self参数,由类自动传入,不需要手动传入
__init__ 类的构造函数
类的继承,父类由括号包含起来
class child(parent):
父类的constructor函数不会被子类自动调用,需要显式的调用。
阅读(1184) | 评论(0) | 转发(0) |