Hi @ all
I need a little bit help with a tricky problem ...
Here�s the situation:
We�ve 2 MySQL-Servers, one is productive, the other is Backup.
At the productive Server there runs every 2 hours a cron Job which does a Dump from MySQL-DB with script 'automysqlbackup.sh' and
copy it then via rsync to the Backup-Server,
so at the Backup there�re the following files:
Sep 15 08:58 daily_test_2014-09-15_08h58m_Monday.sql.gz
Sep 15 10:58 daily_ test _2014-09-15_10h58m_Monday.sql.gz
Sep 15 12:58 daily_ test _2014-09-15_12h58m_Monday.sql.gz
Sep 15 14:58 daily_ test _2014-09-15_14h58m_Monday.sql.gz
Sep 15 16:58 daily_ test _2014-09-15_16h58m_Monday.sql.gz
Sep 15 18:58 daily_ test _2014-09-15_18h58m_Monday.sql.gz
Sep 15 20:58 daily_ test _2014-09-15_20h58m_Monday.sql.gz
Sep 15 22:58 daily_ test _2014-09-15_22h58m_Monday.sql.gz
Sep 16 00:58 daily_ test _2014-09-16_00h58m_Tuesday.sql.gz
Sep 16 02:58 daily_ test _2014-09-16_02h58m_Tuesday.sql.gz
Sep 16 04:58 daily_ test _2014-09-16_04h58m_Tuesday.sql.gz
Sep 16 06:58 daily_ test _2014-09-16_06h58m_Tuesday.sql.gz
Now the problem:
I�ve to import the newest MySQL-Dump-File ( in this case above the file
Sep 16 06:58 daily_ test _2014-09-16_06h58m_Tuesday.sql.gz )
automatically in the DB 'test';
so I think the procedure is:
- have to look which one ist the newest file ( my problem )
- unzip this file
- import via mysql
- do a mysqlcheck
- send a mail to root that import and check is fine
The points 2-5 I would do the following way:
via cron Script 'mysqlimport.sh':
/bin/echo "--------------------------------------------"
/bin/date
echo Script "MySQL-Import"
cd /var/mysql_backup
gunzip (procedure to find out which file is newest) && mysql -u root test < Sep 16 06:58 daily_test_2014_09-16_06h58m_Tuesday.sql && mysqlcheck test
the output in Logfile 'mysqlimport.log'
root /root/mysqlimport.sh >> /var/log/mysqlimport.log
then do a tail of the last lines from 'mysqlimport.log' via script 'mysqlimport2.sh'
tail -50 /var/log/mysqlimport.log | awk '{ print $0 "\x0c";}'
at last send via cron to root
/root/mysqlimport2.sh | mail -r root -s "Result MySQL-Import" root
So I need help with Point 1, because I don�t know how�re the script-commands to find out which is the newest file, because they are different every 2 hours and every day.
Perhaps somebody could help me here?
Thanks in advance.
Regards