Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30133 > unrolled thread

Need to archive a MySQL database using a python script

Started bybruceg113355@gmail.com
First post2012-09-25 16:17 -0700
Last post2012-09-26 13:50 +0200
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Need to archive a MySQL database using a python script bruceg113355@gmail.com - 2012-09-25 16:17 -0700
    Re: Need to archive a MySQL database using a python script Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-25 21:04 -0400
    Re: Need to archive a MySQL database using a python script Hans Mulder <hansmu@xs4all.nl> - 2012-09-26 13:50 +0200

#30133 — Need to archive a MySQL database using a python script

Frombruceg113355@gmail.com
Date2012-09-25 16:17 -0700
SubjectNeed to archive a MySQL database using a python script
Message-ID<3dce14bc-cdec-4bcb-a41d-d5de1ef10bf6@googlegroups.com>
Python Users Group,

I need to archive a MySQL database using a python script.
I found a good example at: https://gist.github.com/3175221

The following line executes however, the archive file is empty.

os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" %
               (user,password,host,database,database+"_"+filestamp))
Where:
  User     = “someUser”
  password = “somePassword”
  host     = “someRemote.database.server”
  database = “someDatabase”

If I execute mysqldump from the command line, an archive is created.

Using Python 2.6 and MySQL-python-1.2.2.win32-py2.6 (MySQLdb)
Mysql-5.5.27 from the command line.

Any ideas?

Thanks,
Bruce

[toc] | [next] | [standalone]


#30138

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2012-09-25 21:04 -0400
Message-ID<mailman.1389.1348621440.27098.python-list@python.org>
In reply to#30133
On Tue, 25 Sep 2012 16:17:24 -0700 (PDT), bruceg113355@gmail.com
declaimed the following in gmane.comp.python.general:

> Python Users Group,
> 
> I need to archive a MySQL database using a python script.
> I found a good example at: https://gist.github.com/3175221
> 
> The following line executes however, the archive file is empty.
> 
> os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" %
>                (user,password,host,database,database+"_"+filestamp))

	Well, First start might be to update from the old os.popen to
subprocess.Popen

	Then I'd suggest working in pieces... Don't do the pipe/gzip part,
just see if the dump is creating a file first.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#30185

FromHans Mulder <hansmu@xs4all.nl>
Date2012-09-26 13:50 +0200
Message-ID<5062ec1b$0$6859$e4fe514c@news2.news.xs4all.nl>
In reply to#30133
On 26/09/12 01:17:24, bruceg113355@gmail.com wrote:
> Python Users Group,
> 
> I need to archive a MySQL database using a python script.
> I found a good example at: https://gist.github.com/3175221
> 
> The following line executes however, the archive file is empty.
> 
> os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" %
>                (user,password,host,database,database+"_"+filestamp))
> Where:
>   User     = “someUser”
>   password = “somePassword”
>   host     = “someRemote.database.server”
>   database = “someDatabase”
> 
> If I execute mysqldump from the command line, an archive is created.
> 
> Using Python 2.6 and MySQL-python-1.2.2.win32-py2.6 (MySQLdb)
> Mysql-5.5.27 from the command line.
> 
> Any ideas?

* If there are shell meta characters in the password, you'd have
need to use single quotes, as in -p'%s'.  Actually, that's true
for any of the parameters, but the password is one most likely
to contain punctuation characters.

* You could try

print("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" %
               (user,password,host,database,database+"_"+filestamp))

and if the result looks okay, copy and paste it to the command line
(do not retype; use copy and paste) and see if it works.

* In your script, add a line

    os.popen("monty_python")

This should produce an error message.  If it doesn't, find out why.

* Check the timestamp of your empty output file.  If it was created
yesterday, then maybe your script is now writing its file in another
directory and you're looking at the output of yesterday's test.


Hope this helps,

-- HansM

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web