Skip to content

Instantly share code, notes, and snippets.

@suranands
Forked from sagar-webonise/pydump.py
Created August 22, 2016 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suranands/dca0dca6caa113a5b65bfefde25ad075 to your computer and use it in GitHub Desktop.
Save suranands/dca0dca6caa113a5b65bfefde25ad075 to your computer and use it in GitHub Desktop.
Python script for taking mysqldump
--- created by sagar shirsath (sagars@weboniselab.com)---
the file pydump contains python code for taking sql dump .
How to run :
Go to folder containing file pydump and run the following command
$python pydump.py
#!/usr/bin/env python
import ConfigParser
import os
import time
import getpass
def get_dump():
print "Enter user:"
user = raw_input()
print "Password will not be visible:"
password = getpass.getpass()
print "Enter host:"
host = raw_input()
print "Enter database name:"
database = raw_input()
filestamp = time.strftime('%Y-%m-%d-%I:%M')
os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" % (user,password,host,database,database+"_"+filestamp))
print "\n-- please have a the dump file in "+database+"_"+filestamp+".gz --"
if __name__=="__main__":
get_dump()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment