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 ...
- 12-28-2011 #1Just 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:
Thanks AlexCode:#!/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.
- 12-29-2011 #2Just 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"
- 12-30-2011 #3Linux 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:
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:#!/bin/bash time mysqldump -uroot -ppassword database table > /tmp/table_$(date +%F_%H%M%S).sql
Code:real 0m0.004s user 0m0.004s sys 0m0.001s


Reply With Quote