Skip to content

Instantly share code, notes, and snippets.

@mirzap
Created August 25, 2013 19:25
Show Gist options
  • Save mirzap/6335744 to your computer and use it in GitHub Desktop.
Save mirzap/6335744 to your computer and use it in GitHub Desktop.
Simple MySQL database backup script
#!/usr/bin/env python
import os,time,getpass
def backup():
filestamp = time.strftime('%Y-%m-%d-%H-%M')
print "Enter username:"
username = raw_input()
print "Enter password:"
password = getpass.getpass()
print "Enter hostname:"
hostname = raw_input()
print "Enter database name:"
database = raw_input()
filename = "%s-%s.sql" % (database, filestamp)
os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" % (username,password,hostname,database,filename))
if __name__=="__main__":
backup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment