|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/usr/bin/env python
#-*-coding:utf8-*-
import
os,sys,time,traceback
import
commands
import
shutil
def
dbBack():
try
:
paths
=
'/usr/home/wangqiang1/dbBackup/'
times
=
time.strftime(
'%Y%m%d%H'
,time.localtime(time.time()))
os.chdir(paths)
cmd
=
'/usr/bin/mysqldump -uadmin -padmin zabbix > /%s/%s_zabbix.sql'
%
(paths,times)
x,y
=
commands.getstatusoutput(cmd)
if
x
=
=
0
:
os.system(
'tar -czvf %s_zabbix.tgz %s_zabbix.sql'
%
(times,times))
shutil.move(
'%s_zabbix.sql'
%
times,
'/dev/null'
)
except
:
print
traceback.format_exc()
def
delDbs():
try
:
paths
=
'/usr/home/wangqiang1/dbBackup/'
os.chdir(paths)
fileall
=
dict
()
files
=
os.listdir(paths)
if
len
(files) >
=
10
:
for
i
in
files:
strtime
=
os.path.getctime(i)
fileall[i]
=
strtime
sortfile
=
fileall.values()
sortfile.sort()
b
=
sortfile[
10
:]
print
b
for
d,s
in
fileall.items():
if
s
in
b:
#shutil.move(d,'/opt/')
#print 'deddlete file %s' %s,d
else
:
print
s,d
except
:
print
traceback.format_exc()
if
__name__
=
=
"__main__"
:
#sc = dbBack()
sd
=
delDbs()
|
本文转自 swq499809608 51CTO博客,原文链接:http://blog.51cto.com/swq499809608/1363305