【python】简单的备份脚本2

简介:
根据日期建立文件夹并存放备份的文件。
# 4. The current day is the name of the subdirectory in the main directory
today = target_dir + time.strftime('%Y%m%d%H%M%S')
#print today
# The current time is the name of the zip archive
now = time.strftime('%Y%m%d%H%M%S')
#print now
# Take a comment from the user to create the name of the zip file comment = raw_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'
    # Notice the backslash!

# 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 (in Unix/Linux) to put the files in a zip archive
zip_command = "zip -qr '%s' %s" % (target, source)
#print zip_command
# Run the backup
if os.system(zip_command) == 0:
    print 'Successful backup to', target
else:
    print 'Backup FAILED'
"backup_ver4.py" 42L, 1449C written                                                                                                                  
[yang@rac1 ~]$ python backup_ver2.py
Enter a comment --> yangql
Successfully created directory /tmp/20110723222525
Successful backup to /tmp/20110723222525/20110723222525_yangql.zip
相关文章
|
28天前
|
Linux Shell Python
Linux执行Python脚本
Linux执行Python脚本
27 1
|
2月前
|
Web App开发 数据采集 自然语言处理
python脚本抢各大平台大额优惠卷
python脚本抢各大平台大额优惠卷
50 0
|
3月前
|
关系型数据库 MySQL 数据库
Python tk dos命令备份mysql数据库
Python tk dos命令备份mysql数据库
25 0
|
17天前
|
JSON 测试技术 持续交付
自动化测试与脚本编写:Python实践指南
【4月更文挑战第9天】本文探讨了Python在自动化测试中的应用,强调其作为热门选择的原因。Python拥有丰富的测试框架(如unittest、pytest、nose)以支持自动化测试,简化测试用例的编写与维护。示例展示了使用unittest进行单元测试的基本步骤。此外,Python还适用于集成测试、系统测试等,提供模拟外部系统行为的工具。在脚本编写实践中,Python的灵活语法和强大库(如os、shutil、sqlite3、json)助力执行复杂测试任务。同时,Python支持并发、分布式执行及与Jenkins、Travis CI等持续集成工具的集成,提升测试效率和质量。
|
24天前
|
存储 监控 异构计算
【Python】GPU内存监控脚本
【Python】GPU内存监控脚本
|
24天前
|
Ubuntu Unix Linux
【Linux/Ubuntu】Linux/Ubuntu运行python脚本
【Linux/Ubuntu】Linux/Ubuntu运行python脚本
|
1月前
|
XML Shell Linux
性能工具之 JMeter 使用 Python 脚本快速执行
性能工具之 JMeter 使用 Python 脚本快速执行
41 1
性能工具之 JMeter 使用 Python 脚本快速执行
|
1月前
|
数据采集 测试技术 Python
Python自动化脚本的魅力与实践
Python自动化脚本的魅力与实践
52 0
|
1月前
|
数据安全/隐私保护 Python
使用Python脚本实现图片合成PDF功能
使用Python脚本实现图片合成PDF功能
28 0
|
1月前
|
安全 数据安全/隐私保护 开发者
如何使用Pyarmor保护你的Python脚本
如何使用Pyarmor保护你的Python脚本
47 0