h3x has asked for the wisdom of the Perl Monks concerning the following question:

Morning Monks, A while back i came here looking for a Mysql backup script and this worked our wonders for a starting point, thanks to penguinfuz at wonderwaylabs dot com. Now Its working exactly the way i want it to on a local machine but there is a catch. I have a remote host running the databases and i want to carry out daily dumps. This is a sample mysqldump script i use to do this manually:  mysqldump --opt --skip-add-drop table --no create-info -u root --p xxxx db_name --tables table_name --where "dateformat(TimeStamp,'%y-%m-%d') = '2008-07-01'"> daily_backup.sql Now in the ideal scenario i want to have this perl script implement DateTime(or any favorable Module) to auto increment the date, ie from 01 to 02 etc etc running as a cron job every day. Any help will be highly appreciated. Cheers

Replies are listed 'Best First'.
Re: Mysql backup using DateTime
by ikegami (Patriarch) on Sep 26, 2008 at 05:07 UTC

    I don't know much about running remote commands, but the date part can be done using:

    use DateTime qw( ); my $date = DateTime ->today( time_zone => 'local' ) ->strftime( '%Y-%m-%d' );

    or just

    use POSIX qw( strftime ); my $date = strftime( '%Y-%m-%d', localtime );

    Well, that's assuming the date is the date on which the cron job is run. Is it something else?

Re: Mysql backup using DateTime
by poolpi (Hermit) on Sep 26, 2008 at 06:45 UTC

    << have this perl script implement DateTime(or any favorable Module) to auto increment the date >>

    #!/usr/bin/perl -w use strict; use DateTime; DateTime->DefaultLocale( 'fr_FR' ); my $dt = DateTime->now; $dt->set_time_zone( 'Europe/Paris' ); $dt->add( days => 1 ); # $dt->subtract( days => 1 ); print $dt->ymd('-');

    hth,
    PooLpi

    'Ebry haffa hoe hab im tik a bush'. Jamaican proverb