homepage Welcome to WebmasterWorld Guest from 54.226.166.224
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Emailing database using cron
mr_nabo




msg:4117638
 11:48 am on Apr 18, 2010 (gmt 0)

Hi,

Trying to figure out how to email the database I create using Cron - the code below is working in that it's creating the backup in the right place:

mysqldump -u USERNAME -pPASSWORD DATABASENAME | gzip > /home/USER/bkupsfolder/mysql-$(date +\%Y-\%m-\%d-\%H.\%M.\%S).gz

Is there an easy way to mod this so that Cron will send the database to a specified email address? By the way, this is a command line going into Cpanel which sets the frequency.

mn

 

lammert




msg:4117721
 5:56 pm on Apr 18, 2010 (gmt 0)

You cannot send binary data as email unless you first encode it to the allowed range of ASCII characters. The old-school method is with uuencode, and the new-school method with MIME. Uuencode is still recognized by most modern email readers and it is the easiest to implement in a command line pipe.

Sending the file directly without storing it in a temporary file:

mysqldump -u USERNAME -pPASSWORD DATABASENAME | gzip | uuencode mysql-$(date +\%Y-\%m-\%d-\%H.\%M.\%S).gz | mail -s "Gzipped backup file" user@example.com

This pipe doesn't create a temporary file. Gzip directly outputs the compressed data to uuencode which encodes it in proper ASCII characters. That output is piped to the mail command line program.

The command line may appear broken on your screen due to screen width limitations. In reality, all commands should be on one line.

mr_nabo




msg:4117924
 6:42 am on Apr 19, 2010 (gmt 0)

This is great, thanks so much for sharing this code!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved