Source

fabulator / src / fabulator / core / mysql.py

"""
    mysql management functions
"""
import datetime
import time

from fabric.api import run

def create_database(conf):
    run("echo 'CREATE DATABASE IF NOT EXISTS %(db)s' | mysql --user=%(user)s --password=%(pw)s" % conf)
    
def drop_database(conf):
    run("echo 'DROP DATABASE %(db)s' | mysql --user=%(user)s --password=%(pw)s" % conf)
    
    
def backup_database(conf):
    """Backups your mysql database"""
    date = datetime.datetime.now()

    conf['backup_fname'] = "%s/backup-%s-%d-%d-%d-%s.sql" % \
        (conf.get('backup'), conf.get('db'), date.day, date.month, date.year, time.time())
    run("mkdir -p %(backup)s" % conf)
    run("""mysqldump --host=%(host)s --user=%(user)s --password=%(pw)s %(db)s > %(backup_fname)s""" % conf)