python 備份日誌(待優化)

2021-08-02 13:32:06 字數 3751 閱讀 1002

root@kali

:~/python/log

# ls

account.log backup.log ext.txt logback.py logger.py logger.pyc

root@kali

:~/python/log

# cat ext.txt

/root/python/atmnew/account.pkl

/root/python/atmnew/logger.pyc

/root/python/atmnew/logger.py

root@kali

:~/python/log

# cat logback.py

#!/usr/bin/python

# --*-- coding:utf-8 --*--

import sys,os,time,logger

source_file = sys.argv[1]

formated_source_file = source_file.split('/')[-1]

backup_dir = '/root/python/atmnew'

backup_to_file = ''

'%s%s_%s.tgz'

'' % (backup_dir,formated_source_file,time.strftime("%y-%m-%d_%h%m%s",time.localtime()))

defrun_backup(runtime="now",exclude_file_name = 'none'):

if len(sys.argv) == 4

: print '-------exclude file mode-------------'

if sys.argv[2] == '-x'

: exclude_file_name = sys.argv[3]

backup_cmd = 'tar cvzfx %s %s %s '

%(backup_to_file,exclude_file_name,source_file)

else:

print '------------normal mode----------------'

#backup_cmd = 'tar cvzf %s %s | wc -l' %(backup_to_file,source_file)

backup_cmd = 'tar cvzf %s %s'

%(backup_to_file,source_file)

run_command = os.system(backup_cmd)

if run_command == 0

: logger.record_log('full backup','success','n/a','test')

else:

logger.record_log('full backup','failure','n/a','test')

run_backup()

root@kali

:~/python/log

# cat logger.py

#!/usr/bin/python

# --*-- coding:utf-8 --*--

import time#匯入時間模組

logfile = 'backup.log'

#定義要使用的日誌檔案account.log

#定義函式包括引數賬戶、花費、描述資訊、利息(預設為0、取款、轉賬有手續費必須帶引數值)

defrecord_log(backup_type,status,files,description = 'null'):

date = time.strftime('%y-%m-%d %h:%m:%s',time.localtime())#取出當前時間

record_line = "%s %s '%s' %s %s\n"

%(date,backup_type,status,files,description)

#記錄當前消費時呼叫函式各個引數時間行為

f = open(logfile,'a')#追加寫入方式開啟日誌account.log

f.write(record_line)#寫入每行函式產生日誌資訊

f.flush()#實時寫入

f.close()#關閉檔案

root@kali

:~/python/log

# cat backup.log

2017-06-1323:

46:45full

backup

'success'

n/a test

2017-06-1323:

59:34full

backup

'success'

n/a test

root@kali

:~/python/log

#

執行:

root@kali

:~/python/log

# cat backup.log

2017-06-1323:

46:45full

backup

'success'

n/a test

root@kali

:~/python/log

# vi ext.txt

root@kali

:~/python/log

# vi logback.py

root@kali

:~/python/log

# python logback.py /root/python/atmnew -x ext.txt

-------exclude file mode-------------

tar: 從成員名中刪除開頭的「/」

/root/python/atmnew/

/root/python

/atmnew/account.py

/root/python/atmnew/record_account.py

/root/python/atmnew/account.log

/root/python/atmnew/pickle_test.py

/root/python/atmnew/::wq

root@kali

:~/python/log

# cat ext.txt

/root/python/atmnew/account.pkl

/root/python/atmnew/logger.pyc

/root/python/atmnew/logger.py

root@kali

:~/python/log

# root@kali

:~/python

# ls atmnew

account.log account.pkl account.py logger.py logger.pyc pickle_test.py record_account.py ::wq

root@kali

:~/python

# ls

atmnewaccount.py_2017-06-13_234645.tgz

atmnewatmnew_2017-06-13_235934.tgz

root@kali

:~/python

#

python 使用者登入與鎖定錯誤賬戶(待優化)

此文參考 root kali python atm4 vi logocopy.py usr bin python coding utf 8 import sys,os,getpass,tab,time,datetime defvartime d1 datetime.datetime 2017,6,1...

php下呼叫 Ffmpeg 待優化

背景是公司有乙個業務需求是用到了科大訊飛的文字語音轉換,需要對科大訊飛轉換出來的語音檔案做合成。在linux下現有的音訊合成軟體用的最多的應該也就是ffmpeg了,所以選擇了ffmpeg。雖然在開發前就對ffmpeg的php拓展n年沒更新有所了解,所以也沒打算用,就想直接通過exec 執行shell...

python copy模組 待優化的功能

deep2type是乙個字典,point dict deep2type之後,如果修改point dict,也會對deep2type造成影響,請問如何解決 可以通過深度複製的方法,把源資料複製,得到乙個新的資料物件,操作新資料物件不會影響到源資料,詳情如下 import copy point dict...