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
46
47
48
49
50
51
52
| #!/usr/bin/env python
#backup the gtshop
#author:ley
#encoding=utf8
#date:2015-06
import os,sys,datetime,time
from stat import *
#mysqlbackup user
User = 'root'
#mysqlbackup password
Password = 'root'
#mysqlbackup command
Mysqlcommand = '/usr/local/mysql/bin/mysqldump'
#gzip command
Gzipcommand = '/bin/gzip'
#backup mysql database
Mysqldata = ['gtshop']
#backup dir
Tobackup = '/home/gtshop_backup/'
for DB in Mysqldata:
#backup file name
Backupfile = Tobackup + DB + '-' + time.strftime('%Y-%m-%d') + '.sql'
#gzip file name
Gzipfile = Backupfile + '.gz'
if os.path.isfile(Gzipfile):
print Gzipfile + "is already backup"
else:
#backup command
Back_command = Mysqlcommand + ' -u' + User + ' -p' + Password + ' --events ' + ' --master-data=2 ' + ' --single-transaction ' + DB + ' > ' + Backupfile
if os.system(Back_command) == 0:
print 'Sucessful backup gtshop'
else:
print 'Backup failed'
#gzip command
Gzip_command = Gzipcommand + ' ' + Backupfile
if os.system(Gzip_command) == 0:
print 'sucessful gzip gtshop'
else:
print 'gzip failed'
|