← Back to team overview

mylvmbackup-discuss team mailing list archive

patch: use ~/.my.cnf for the password

 

I don't like to store the admin password for MySQL many places, so this
patch will use $HOME/.my.cnf if no password has been provided and the
file exists.

-- 
Kjetil T. Homme
Redpill Linpro AS - Changing the game
--- mylvmbackup-0.11/mylvmbackup        2008-11-23 14:14:51.000000000 +0100
+++ files/mylvmbackup   2009-05-06 17:38
@@ -190,6 +230,12 @@
 
 run_hook ("preconnect");
 log_msg ("Connecting to database...", LOG_INFO);
+
+$ENV{HOME} = (getpwuid($<))[7] unless defined $ENV{HOME};
+if (-r "$ENV{HOME}/.my.cnf" && !$password) {
+    $dsn .= ";mysql_read_default_file=$ENV{HOME}/.my.cnf";
+    $user = $password = undef;
+}
 my $dbh= DBI->connect($dsn,$user,$password);
 if (!$dbh)
 {


Follow ups