Send automatic backup email

9 replies
Hi guys,

I manage a number client websites and automatically run a cron job to backup the sites daily. It sends the backup file directly to me via email.

I want to send each client one email daily notifying them of the backup. It does NOT need to be linked directly to the backup (i.e. it doesn't need to be CC'd from the email I receive). I basically just need way to send a basic email once a day (there are only about 15 clients).

I'm assuming through a PHP mail method on my local server? Or should this be run through a CRON?


Craig Maclean
#automatic #backup #email #send
  • Profile picture of the author hhunt
    I don't think you'd need to change much of the script you already have to accomplish what you want. In fact, there are lots of ways you could approach it, one would be to run your script using cron job. But in the script itself, loop through all the accounts backing each one up and if successful, send an email to the account holder associated with the account

    However, if you can't modify the script to run in a loop, I would suggest you manually create separate script for each account and a cron job for each of those scripts. This way, it is easier to manage individual file without getting in the way of the rest.

    Finally, whatever you method you go with, it would have to be run through cron job which come as standard on any UNIX/Linux server.
    {{ DiscussionBoard.errors[1433586].message }}
  • Profile picture of the author cmaclean
    Thanks HHunt. Couple things:

    I'm currently using phpMySQLAutoBackup automates the backup of MySQL databases (exports your db structure and data in seconds) to create the backup file. I actually don't want to email them the backup file. I just want to notify them that a backup has actually taken place. I'm running the phpmysqlautobackup with a cron job currently.

    Do you know of a simple php script which I can run with cron to accomplish this?

    {{ DiscussionBoard.errors[1433995].message }}
  • Profile picture of the author hhunt
    I have never used phpMySQLAutoBackup so I don't know how it works. That said, I think you'd need to modify the script to remove the sending of backed-up file to your users, instead, it should just send a notification email.

    The problem is that I don't use PHP myself, most of my work is done in either Java or Python. I don't know any other PHP script you can use am afraid.
    {{ DiscussionBoard.errors[1434941].message }}
    • Profile picture of the author Elliott Bean
      $message= " Here is the message";
      $subject = "message subject";
      $headers= "From: you <> \n";
      $headers.= "Reply-To:";
      mail("",$subject,$message,$headers );

      If you modify that code it could send the client an email, then you could set a cron job to run the script right after you've done the backup or include that code amongst the code that does the backup.

      best of luck

      {{ DiscussionBoard.errors[1435794].message }}
  • Profile picture of the author HomeBizNizz
    If you run Joomla: JBackup
    Works like a charm...

    Use a mail forwarder that sends to multiple adresses, should work.
    {{ DiscussionBoard.errors[1435938].message }}
    • Profile picture of the author Jeff Poulton
      Another solution that wouldn't involve a single code change would be to set up a mail filter. For example, I use gmail and have custom filters to send specific emails to specific people as part of my business automation. When you receive a backup for a specific client (presumably identified as part of the email subject) simply have a rule that forwards that email to the client's email address.
      {{ DiscussionBoard.errors[1442127].message }}
  • Profile picture of the author cmaclean
    Thanks Elliot and Jeff. I'll work with one of these to see which better suits.
    {{ DiscussionBoard.errors[1445529].message }}
  • Profile picture of the author Mr. Enthusiastic
    Originally Posted by cmaclean View Post

    Hi guys,
    I manage a number client websites and automatically run a cron job to backup the sites daily. It sends the backup file directly to me via email.
    Craig, why don't you just modify the existing script? If the backup is successful, it already sends you an email. Just add a line to the script at the point to send the notification to your client that their daily backup is successful. I'd also add an ELSE clause that if the backup does not complete successfully, only you get an email. You or an assistant can manually validate those backups as needed, then retrigger the cron job for those clients and any newly successful backups should get the client email auto-generated. Does this make sense?

    {{ DiscussionBoard.errors[1447121].message }}
  • Profile picture of the author cmaclean
    I ended up just writing a quick PHP script with a mail function and have set a cron job on each server. Thanks guys!
    {{ DiscussionBoard.errors[1447456].message }}

Trending Topics