[mylvmbackup] create if not exist proposal

And finally, if a directory doesn't exist, create it.  Could probably
turn the 3rd parameter into a config variable.

Think that's all for now. Great script otherwise! We will be using it
plus our modifications on about 200+ customer MySQL servers in the
coming few months.

Cheers.

Matthew Boehm
Senior MySQL DBA, The Planet - Northstar Managed Hosting
Certified MySQL 5.0 DBA
Office: 281-714-4018
Mobile: 832-253-8258
Email: mboehm@xxxxxxxxxxxxx

[root@15000Dmys01 trunk]# bzr diff
=== modified file 'trunk/mylvmbackup.pl.in'
--- trunk/mylvmbackup.pl.in     2008-09-03 20:06:47 +0000
+++ trunk/mylvmbackup.pl.in     2008-09-05 17:15:48 +0000
@@ -142,10 +142,10 @@
 my $snapshot_created = 0;

 # Check the backupdir, it must exist, and it must be readable/writable
-check_dir($backupdir, 'backupdir') unless ($backupdir =~ /::/ and
$backuptype eq 'rsync');
+check_dir($backupdir, 'backupdir', 1) unless ($backupdir =~ /::/ and
$backuptype eq 'rsync');

 # Check the mountdir, it must exist, and be readable/writeable
-check_dir($mountdir, 'mountdir');
+check_dir($mountdir, 'mountdir', 1);

 # Append the prefix to the mountdir, to allow multiple parallel
backups. The
 # extra / is to ensure we go a level under it. An empty prefix is
disallowed.
@@ -709,7 +709,17 @@
 #
 sub check_dir
 {
- my ($dirname,$optioname) = @_;
+ my ($dirname,$optioname,$create) = @_;
+ if (!(-d $dirdame) && create == 1)
+ {
+   eval { File::Path::mkpath($dirname) };
+   if($@)
+   {
+     log_msg("The directory for '$optionname' ($dirname) does not exist
and I was unable to create id.", LOG_ERR);
+     &help;
+   }
+ }
+
  unless ( (-d $dirname) and
      (-w $dirname) and (-r $dirname) and  (-x $dirname))
  {

Other related posts: