Created
June 25, 2014 12:42
-
-
Save llazzaro/2a1e9df272b1033f1308 to your computer and use it in GitHub Desktop.
Fabric script for mysql backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def vps(): | |
env.hosts = ['apps.myvps.com'] | |
env.user = 'app' | |
env.dbname = 'blog' | |
env.dbuser = 'blogger' | |
env.dbpass = 'password' | |
def backup(): | |
require('hosts', provided_by=[vps]) | |
require('dbname') | |
require('dbuser') | |
require('dbpass') | |
date = time.strftime('%Y%m%d%H%M%S') | |
fname = '/tmp/%(database)s-backup-%(date)s.xml.gz' % { | |
'database': env.dbname, | |
'date': date, | |
} | |
if exists(fname): | |
run('rm "%s"' % fname) | |
run('mysqldump -u %(username)s -p%(password)s %(database)s --xml | ' | |
'gzip > %(fname)s' % {'username': env.dbuser, | |
'password': env.dbpass, | |
'database': env.dbname, | |
'fname': fname}) | |
get(fname, os.path.basename(fname)) | |
run('rm "%s"' % fname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is there any other thing required to run this via fabric? because when i tried it with fab backup it says, " global name 'require' is not defined "