[mylvmbackup] Re: creating file paths as patterns

Figured this one out. Instead of

 

$d = `/bin/date +$d` if $dateparse;

 

Just do:

 

$d = time2str($d, time) if $dateparse;

 

I think that's much "safer".

 

-Matthew

 

From: Boehm, Matthew 
Sent: Tuesday, September 02, 2008 4:14 PM
To: mylvmbackup@xxxxxxxxxxxxx
Subject: creating file paths as patterns

 

For our backup purposes, we need to create the following structure:

 

/var/backups/mysql/YYYYMMDD/

 

Inside this dir structure will be the full backup created by mylvmbackup
and all of the binary logs until the next full backup. Binlogs will be
rotated every 15 min and rsync'd into this dir by a simple shell script.

 

I've made a change to clean_dirname() to accept an optional 2nd
parameter, that if true, will send the file name through /bin/date. I'm
no perl guru so perhaps someone who is has a better way to do this than
`shell` escaping the command.

 

sub clean_dirname

{

        my ($d, $dateparse) = @_;

        $d = `/bin/date +$d` if $dateparse;

        $d =~ s/^\s*//g;

        $d =~ s/\s$//g;

 

        return File::Basename::dirname($d . '/foo')

}

 

Since these will become unattended backups, we also needed the script to
be able to create the directory structure on its own. Thus check_dir()
was altered with a similar 3rd optional parameter:

 

sub check_dir

{

        my ($dirname, $optioname, $create) = @_;

        if (!(-d $dirname) && $create == 1)

        {

                eval { File::Path::mkpath($dirname) };

                if($@)

                {

                        log_msg ("The directory $dirname does not exist
and I was unable to create it.", LOG_ERR);

                        &help;

                }

        }

 

        < ...rest unchanged.. >

}

 

Again, if there's a better way/more appropriate way, I'd love to hear
it.

 

Cheers,
Matthew

 

Matthew Boehm

Senior MySQL Database Administrator

The Planet - Northstar Managed Hosting

Office: 281-714-4018

Mobile: 713-392-8748

Email: mboehm@xxxxxxxxxxxxx <mailto:jtillotson@xxxxxxxxxxxxx> 

 

Other related posts: