#! /usr/bin/env python# coding: utf-8importosimportsysfromdatetimeimport*importtime#mysql's pathmysql_path='/usr/local/mysql/bin/'#edit this if your mysql username and password is not like this:mysql_username='root'mysql_password='xxxxxx'#backup pathbackup_path='mysqlbackup/'defvalidate_backup_path():ifos.path.exists(backup_path)==False:print"I create a directory here: %s "%backup_pathos.mkdir(backup_path)defbackup_all_databases():filename="all_%s.sql"%(datetime.utcfromtimestamp(time.time()))os.system("%smysqldump -u%s -p%s --all-databases > '%s%s'"%(mysql_path,mysql_username,mysql_password,backup_path,filename))if__name__=="__main__":validate_backup_path()backup_all_databases()print"finish!!!"