Created
August 25, 2013 19:25
-
-
Save mirzap/6335744 to your computer and use it in GitHub Desktop.
Simple MySQL database backup script
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
#!/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