Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4025548
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:51:38+00:00 2026-05-20T10:51:38+00:00

I would like to run a cron job to backup some mysql databases by

  • 0

I would like to run a cron job to backup some mysql databases by piping the output to a file and then emailing it.

Will the following work?

15 2 * * * root mysqldump -u root -pPASSWORD --all-databases | \
    gzip > /database_`data'+%m-%d-%Y'`.sql.gz | \
    mail -s "Report 05/06/07" user@example.com < /database_`data'+%m-%d-%Y'`.sql.gz
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:51:38+00:00Added an answer on May 20, 2026 at 10:51 am

    There are a couple of problems with your script, I have altered it below, note carefully the change of spaces, spelling of date and replacement of | for ;.

    The most interesting problem however is that mail unfortunately can’t send attachments. You could use uuencode to embed the file in the mail using:

    15 2 * * * root mysqldump -uroot -pPASSWORD --all-databases | gzip > /database_`date +'%m-%d-%Y'`.sql.gz ; uuencode /database_`date +'%m-%d-%Y'`.sql.gz /dev/stdout | mail -s "Report 05/06/07" user@domain.com
    

    Or if you want to have a proper MIME attachment use (You will need MetaMail installed):

    15 2 * * * root mysqldump -uroot -pPASSWORD --all-databases | gzip > /database_`date +'%m-%d-%Y'`.sql.gz ; metasend -b -t user@domain.com -s "Report 05/06/07" -m application/gzip -f /database_`date +'%m-%d-%Y'`.sql.gz
    

    Or as above with mpack installed, instead of MetaMail:

    15 2 * * * root mysqldump -uroot -pPASSWORD --all-databases | gzip > /database_`date +'%m-%d-%Y'`.sql.gz ; mpack -s "Report 05/06/07" -c application/gzip /database_`date +'%m-%d-%Y'`.sql.gz user@domain.com
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run a job through cron that will be executed every
I would like to write a cron job that has to run a PHP
I would like to execute a MySQL command in a shell script/cron job that
I would like to build an application that will run on a web, this
I would like to schedule a cron task to run every hour, but only
I have some small python 2.6 scripts built.... Now, I would like run them
I would like to run some command (e.g. command ) using perl's system() .
I would like to call a cron job from within a PHP script. I
I would like to run multiple copies of my application and force the first
I have a servlet that I would like to run within ColdFusion MX 7.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.