python 備份檔案指令碼

2021-06-14 15:28:04 字數 523 閱讀 1140

#!/usr/bin/env python

# filename: backup_ver1.py

import os

import time

source=[r'd:\python\test',r'd:\python\test1']

target_dir='d:\\python\\test2\\' #remember to change this to what you will be using

target=target_dir+time.strftime('%y%m%d%h%m%s')+'.zip'

zip_command = "zip -qr %s %s" % (target, ' '.join(source))
if os.system(zip_command)==0:

print 'successful backup to',target

else:

print 'backup failed'

Python小指令碼 001 備份檔案

練習適用於linux,類unix系統,一步乙個腳印提高python 001.類unix系統中用zip命令將檔案壓縮備份至 temporary 目錄下 import osimport time old files home zhg aa.py home zhg bb.py target dir tem...

linux指令碼實現備份檔案

要求 編寫乙個指令碼實現備份 var log目錄下的所有檔案到 bak目錄下,要求檔名是包含當天日期,精確到秒,檔名例如 2019 6 6 2 30 20 log.tar.gz。同時要求刪除 bak目錄下七天前的備份檔案,只保留最近7天的 bin bash 獲得當前的時間 ctime date y ...

python 簡單備份檔案指令碼v2 0

1.0中使用os.system來壓縮會依賴計算機之外的程式,使用zipfile內建模組來建立壓縮文件會是乙個很好的改進,此外使用日期時間來命名壓縮檔案不是很全面,希望可以增加使用者輸入檔名以及增強檔案歸檔功能。將指定檔案新增到zip文件中。filename為檔案路徑,arcname為新增到zip文件...