Need to archive a MySQL database using a python script

Discussion in 'Python' started by bruceg113355@gmail.com, Sep 26, 2012.

  1. Guest

    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
     
    , Sep 26, 2012
    #1
    1. Advertising

  2. On Tue, 25 Sep 2012 16:17:24 -0700 (PDT),
    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
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Sep 26, 2012
    #2
    1. Advertising

  3. Hans Mulder Guest

    On 26/09/12 01:17:24, 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
     
    Hans Mulder, Sep 26, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rainer
    Replies:
    3
    Views:
    477
    Swapnajit Mittra
    Apr 26, 2005
  2. Rainer
    Replies:
    3
    Views:
    469
    Mike Treseler
    Apr 24, 2005
  3. Hallgeir Stuenes

    Database vs XML document archive

    Hallgeir Stuenes, May 13, 2006, in forum: XML
    Replies:
    3
    Views:
    597
    Joe Kesselman
    May 13, 2006
  4. dave
    Replies:
    4
    Views:
    1,405
    Steve Holden
    Nov 18, 2010
  5. julian
    Replies:
    8
    Views:
    489
    Avatar
    Apr 6, 2006
Loading...

Share This Page