python使用7z解壓軟件備份文件腳本分享
要求安裝:
1.Python
2.7z解壓軟件
backup_2.py
# Filename: backup_2.py
'''Backup files.
Version: V2, based on Python 3.3
Usage: backup.py -s:"dir1|dir2|..." -t:"target_dir" [-c:"comment"]
-s: The source directories.
-t: The target directory.
-c: Optional, any comment.
Examples:
backup.py -s:"c:\\src\\F1|c:\\src\\F2|c:\\src\\F 3" -t:"c:\\backup"
backup.py -s:"c:\\src\\F 3" -t:"c:\\backup" -c:"For sample"'''
import os
import sys
import time
# Read sys.argv
print(sys.argv)
if len(sys.argv) < 2:
print(__doc__)
sys.exit()
source=[]
target_dir=''
comment=''
for arg in sys.argv:
if arg.startswith('-s:'):
source=arg[3:].split('|')
print(source)
elif arg.startswith('-t:'):
target_dir=arg[3:]+os.sep
print(target_dir)
elif arg.startswith('-c:'):
comment=arg[3:]
print(comment)
for i in range(0, len(source)):
source[i] = "\"" + source[i] + "\""
print(source[i])
# Make the file name with the time and comment
today=target_dir+time.strftime('%Y%m%d')
now=time.strftime('%H%M%S')
if len(comment)==0: # check if a comment was entered
target=today+os.sep+now+'.7z'
else:
target=today+os.sep+now+'_'+\
comment.replace(' ','_')+'.7z'
# Create the subdirectory by day
if not os.path.exists(today):
os.mkdir(today) # make directory
print('Successfully created directory',today)
# zip command
zip_command="7z a %s %s" %(target,' '.join(source))
print(zip_command)
# Run the backup
if os.system(zip_command)==0:
print('Successful backup to',target)
else:
print('Backup FAILED')
- Python解析nginx日志文件
- python實(shí)現(xiàn)分析apache和nginx日志文件并輸出訪客ip列表的方法
- Python 分析Nginx訪問(wèn)日志并保存到MySQL數(shù)據(jù)庫(kù)實(shí)例
- Python實(shí)現(xiàn)備份文件實(shí)例
- python在windows下實(shí)現(xiàn)備份程序?qū)嵗?/a>
- python實(shí)現(xiàn)數(shù)通設(shè)備tftp備份配置文件示例
- python備份文件以及mysql數(shù)據(jù)庫(kù)的腳本代碼
- python備份文件的腳本
- Python Mysql自動(dòng)備份腳本
- 淺析python 定時(shí)拆分備份 nginx 日志的方法
相關(guān)文章
python中round函數(shù)保留兩位小數(shù)的方法
在本篇內(nèi)容里小編給各位分享的是一篇關(guān)于python中round函數(shù)保留兩位小數(shù)的方法及相關(guān)知識(shí)點(diǎn),有興趣的朋友們可以學(xué)習(xí)下。2020-12-12
PyTorch學(xué)習(xí)筆記之回歸實(shí)戰(zhàn)
這篇文章主要介紹了PyTorch學(xué)習(xí)筆記之回歸實(shí)戰(zhàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05
Postman安裝與使用詳細(xì)教程 附postman離線安裝包
這篇文章主要介紹了Postman安裝與使用詳細(xì)教程 附postman離線安裝包,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03
Python3.9.0 a1安裝pygame出錯(cuò)解決全過(guò)程(小結(jié))
這篇文章主要介紹了Python3.9.0 a1安裝pygame出錯(cuò)解決全過(guò)程(小結(jié)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
Python?NumPy教程之?dāng)?shù)組的創(chuàng)建詳解
這篇文章主要為大家詳細(xì)介紹了Python?NumPy中數(shù)組的創(chuàng)建方式,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Python有一定幫助,需要的可以參考一下2022-08-08
pycharm 關(guān)閉search everywhere的解決操作
這篇文章主要介紹了pycharm 關(guān)閉search everywhere的解決操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-01-01
徹底吃透理解Python基礎(chǔ)33個(gè)關(guān)鍵字詳細(xì)教程
這篇文章主要為大家介紹了徹底吃透理解Python中33個(gè)關(guān)鍵字的詳細(xì)教程,有需要打好Python基礎(chǔ)的同學(xué)可以借鑒參考下,希望能成為您成功路上的一塊墊腳石2021-10-10
python3使用urllib示例取googletranslate(谷歌翻譯)
這篇文章主要介紹了使用urllib取googletranslate(谷歌翻譯)的示例,通過(guò)這個(gè)谷歌翻譯示例學(xué)習(xí)python3中urllib的使用方法,2014-01-01
python自動(dòng)化測(cè)試用例全對(duì)偶組合與全覆蓋組合比較
這篇文章主要為大家介紹了python自動(dòng)化測(cè)試用例全對(duì)偶組合與全覆蓋組合比較,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06

