#!/usr/bin/env python
# encoding: utf-8
import os,time,sys
bakup_dir = '/home/bak/mysql'
current_time = time.strftime('%Y%m%d%H%M%S')
user = 'root'
password = 'root'
database = ['mysql','aaa']
if os.path.exists(bakup_dir):
print "The path %s exists" % bakup_dir
else :
os.makedirs(bakup_dir)
print "The path %s create sucessful" % bakup_dir
os.chdir(bakup_dir)
for i in range(len(database)):
a = database[i]
mysqlbak_cmd = "mysqldump -u%s -p%s --default-character-set=utf8 %s > %s%s.sql" % (user,password,a,current_time,a)
os.system(mysqlbak_cmd)
print "backup sucessful"