Skip to content

Instantly share code, notes, and snippets.

@llazzaro
Created June 25, 2014 12:42
Show Gist options
  • Save llazzaro/2a1e9df272b1033f1308 to your computer and use it in GitHub Desktop.
Save llazzaro/2a1e9df272b1033f1308 to your computer and use it in GitHub Desktop.
Fabric script for mysql backup
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)
@hardikdangar
Copy link

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 "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment