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訪問日志并保存到MySQL數(shù)據(jù)庫實(shí)例
- Python實(shí)現(xiàn)備份文件實(shí)例
- python在windows下實(shí)現(xiàn)備份程序?qū)嵗?/a>
- python實(shí)現(xiàn)數(shù)通設(shè)備tftp備份配置文件示例
- python備份文件以及mysql數(shù)據(jù)庫的腳本代碼
- python備份文件的腳本
- Python Mysql自動(dòng)備份腳本
- 淺析python 定時(shí)拆分備份 nginx 日志的方法
相關(guān)文章
python實(shí)現(xiàn)保存網(wǎng)頁到本地示例
這篇文章主要介紹了python實(shí)現(xiàn)保存網(wǎng)頁到本地示例,需要的朋友可以參考下2014-03-03Python中numpy.pad()函數(shù)的使用詳解
這篇文章主要介紹了Python中numpy.pad()函數(shù)的使用詳解,在卷積神經(jīng)網(wǎng)絡(luò)中,為了避免卷積運(yùn)算導(dǎo)致輸出圖像縮小和圖像邊緣信息丟失,常常采用圖像邊緣填充技術(shù),即在圖像四周邊緣填充0,使得卷積運(yùn)算后圖像大小不會(huì)縮小,同時(shí)也不會(huì)丟失邊緣和角落的信息,需要的朋友可以參考下2023-10-10Requests什么的通通爬不了的Python超強(qiáng)反爬蟲方案!
今天帶大家學(xué)習(xí)Requests什么的通通爬不了的Python超強(qiáng)反爬蟲方案,文中有非常詳細(xì)的圖文介紹及代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們有很好的幫助,需要的朋友可以參考下2021-05-05Python實(shí)現(xiàn)語音識(shí)別vosk的示例代碼
Vosk是一個(gè)功能強(qiáng)大且易于使用的語音識(shí)別工具包,它提供了Python綁定,使得在Python中使用Vosk變得非常方便,本文主要介紹了Python實(shí)現(xiàn)語音識(shí)別vosk的示例代碼,具有一定的參考價(jià)值,感興趣的可以了解一下2023-12-12PyCharm連接遠(yuǎn)程服務(wù)器的超級(jí)詳細(xì)教程
Pycharm可以與服務(wù)器建立連接,把相應(yīng)的項(xiàng)目同步到服務(wù)器上,下面這篇文章主要給大家介紹了關(guān)于PyCharm連接遠(yuǎn)程服務(wù)器的超級(jí)詳細(xì)教程,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12Python基礎(chǔ)Lists和tuple實(shí)例詳解
這篇文章主要為大家介紹了Python基礎(chǔ)Lists和tuple實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08