Script Archive: Mysql Backup

!/usr/bin/perl -w
 use strict;
 Backup - Script used to backup MySQL databases to an NFS share.
 VERSION: 1.4
 DATE: 12032010
 AUTHOR: packetmad
 This is a Freebsd 4.x-centric script. It may run on other
 versions of Freebsd, or any other BSD for that matter, but I
 wrote it on a Freebsd 4.7 system. It's not even guaranteed
 to run on that.
 Speaking of guarantees, warranties, etc., there ain't one, so
 don't even try. :P
 I am not responsible for the output of this script, nor am I
 responsible for any damage or data loss as a result of using
 this script. In short, I am not responsible for anything
 regarding this script.
 Furthermore, I am not responsible if this script causes
 Your dog to die, your wife to leave you, or
 your truck to break down.
 I am releasing this script under the conventions of the BSD
 license. You can use it, modify it, sleep with it, or
 whatever. If you do find this script useful or have
 suggestions on a better way to do some things contained here
 in, I welcome all correspondence.
 The latest version of this script can be obtained at:
 http://tech.kulish.com
 USE THIS SCRIPT AT YOUR OWN RISK!!!!!!!!!!!!!!!!!!
 Change Log
 v1.1
 Date: 11302002
 Initial Release, absolutely BUG FREE! :)
 v1.2
 Date: 12152005
 Added compression functionality
 Added naming of backup files by date
 Changed longterm storeage directory for 1back to store1
 v1.3
 Date: 11012009
 Cleaned up naming
 Adjusted $bdir variable name for readability in script
 v1.4
 Date: 12032010
 Added structured email header
 Changed (again) longterm storage to archive
 Testing against MariaDB, success
 Change Control:
 01/05/2011  Removed unused drupal databases
 #
 Declare variables and arrays.
 #
 my (
 $bdir, $sysname, $logfile, %databases, $key, $database, $rightnow, $headersysname, $headero, $slevel, $headerdate, $subjectdate
 );
 chomp ( $headersysname = /bin/hostname -f );
 chomp ( $headero = /bin/uname -o );
 chomp ( $slevel = /bin/uname -r );
 chomp ( $headerdate = /bin/date );
 chomp ( $subjectdate = /bin/date +%m%d%Y:%H%M.%S );
 $bdir = '/backup/databases';
 chomp ( $sysname = /bin/uname -n );
 chomp ( $rightnow = /bin/date +%m-%d-%G_%H%M_ );
 print $rightnow;
 Databases we want to backup and associated archive names.
 Database => sql file pairs.
 %databases = (
 'mon_observium' => 'mon_observium.sql',
 'wp_kulishcars' => 'wp_kulishcars.sql',
 'wp_kulishfamily' => 'wp_kulishfamily.sql',
 'wp_kulishtech' => 'wp_kulishtech.sql',
 'mysql' => 'mysql.sql'
 );
 #
 Backup Section
 #
 foreach $key (sort keys %databases) {
 $database = $databases{$key};
 /usr/bin/mysqldump $key > $bdir/$database;}
 #
 Compression Functionality
 #
 foreach $key (sort keys %databases) {
 $database = $databases{$key};
 /bin/gzip -c $bdir/$database > $bdir/$rightnow$database.gz;}
 scp them to the fileshare
 scp $bdir$sysname/*.gz USERNAME\@SERVER:databases;
 #
 Clean backup dir
 #
 rm -rf $bdir/*.sql;
 /bin/mv $bdir/*.gz $bdir/archive;
 Build Header
 /bin/echo "" > /var/log/mysql-backup.log;
 /bin/echo "Node: $headersysname" >> /var/log/mysql-backup.log;
 /bin/echo "OS:   $headero $slevel" >> /var/log/mysql-backup.log;
 /bin/echo "Date: $headerdate" >> /var/log/mysql-backup.log;
 /bin/echo "" >> /var/log/mysql-backup.log;
 /bin/ls -lh /backup/databases | /bin/grep sql >> /var/log/mysql-backup.log;
 Send email notification
 /bin/cat /var/log/mysql-backup.log | /usr/bin/mailx root -s "mysql-backup.pl: $subjectdate";