Test System Environment Windows 2003 python 2.5.1 mysql 5.0.1
Should only work for Win because CMD is called.
Incremental backups, because of self-use and a small database.
Back with demand plus self-testing and automatic deletion of 5 days old.
#!/usr/bin/env python
#encoding=utf-8
#Mysql auto backup
#Author: vane
import os, sys, datetime
reload(sys)
('utf-8')
backup_path = """d:\\mysql_backup_files"""
dbhost = "localhost"
dbname = "dabatase name" # database name
dbuser = "root" # username
dbuserpw = "123456" # password
dbcharset = 'utf8' # output file encoding, default UTF8
now = str(())[:10]
backup_command = """mysqldump -B %s -h%s -u%s -p%s --default_character-set=%s --opt>%s\dbbackup_%s_%\n""" % (dbname, dbhost, dbuser, dbuserpw, dbcharset, backup_path, dbname, now)
a, b = os.popen2('cmd')
(backup_command)
()
()
()
print "Done!"