Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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()
@evariaayu

This comment has been minimized.

Copy link

evariaayu commented Apr 25, 2015

where's the folder for ouput file? is the same with pydump?

@shadow1349

This comment has been minimized.

Copy link

shadow1349 commented Oct 29, 2015

If the folder output is unspecified Python is smart enough to put it in the current working directory meaning youll have the dump in the same place as you store this file.

@gurutux

This comment has been minimized.

Copy link

gurutux commented May 27, 2017

Hey there,

Thanks for your effort.
I have upgraded the script to Python 3 here: https://github.com/gurutux/GuruTux/blob/master/MySQL/pydump.py

@raju234007

This comment has been minimized.

Copy link

raju234007 commented Mar 15, 2018

Hi Team,
I'm maintaining MySQL with 7 databases as per my application needs by excluding default dbs. Now I want one Python script to take mysql dump, it should give below requirements.

  1. It should take dump all 7 databases into one backup folder, by excluding 5 tables from one of the databases.
  2. It should make backup folder as zip with timestamp.
  3. Upload this zip file to the AWS S3.
  4. I should get mail even this process failed or succeeded.
  5. Delete backup zip files which are existing more than 7 days.
@pradeep-decorist

This comment has been minimized.

Copy link

pradeep-decorist commented Sep 23, 2019

Hey there,

Thanks for your effort.
I have upgraded the script to Python 3 here: https://github.com/gurutux/GuruTux/blob/master/MySQL/pydump.py

given link is not working(404)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.