Find the answer to your Linux question:
Results 1 to 3 of 3
I have created a small script that runs at midnight every night that dumps important individual tables off a database as a backup here is the code: Code: #!/bin/bash #dump ...
  1. #1
    Just Joined!
    Join Date
    Aug 2011
    Posts
    12

    Shell Script for MySQL Dump

    I have created a small script that runs at midnight every night that dumps important individual tables off a database as a backup here is the code:

    Code:
    #!/bin/bash
    #dump tables
    mysqldump -uroot -pmypassword database table > /file location/file.sql
    mysqldump -uroot -pmypassword database table > /file location/file.sql
    What I want to know is if there is a way that I can record the time of the MySQLdump execution and completion.
    Thanks Alex

  2. #2
    Just Joined!
    Join Date
    Oct 2009
    Location
    BeiJing China
    Posts
    12
    #!/bin/bash

    timefile=/path/to/dir/sqlbackup.time
    gettime()
    {
    echo "${1} $(date +"%F %T")" >> ${timefile}
    }

    gettime "Time start"
    mysqldump -u root -p mypassword database table > location/file.sql
    gettime "Time end"

  3. #3
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    I do something similar, and I like to put the timestamp in the dump file itself. I also like to track how long it took. So putting those two things together, I do something like:

    Code:
    #!/bin/bash
    time mysqldump -uroot -ppassword database table > /tmp/table_$(date +%F_%H%M%S).sql
    That would generate a file named something like "table_2011-12-29_232146.sql". The time it took to run would be send to the terminal, e.g.:
    Code:
    real    0m0.004s
    user    0m0.004s
    sys     0m0.001s

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...