Jump to content

Cron Backup


Recommended Posts

I entered the following on the command line:

 

/home/myaccount/etc/automysqlbackup.sh

 

and received the following email message as a result:

 

/bin/sh: line 1: /home/myaccount/etc/automysqlbackup.sh: No such file or directory

 

 

What am I doing wrong?

 

Thanks in advance.

Link to comment
Share on other sites

  • 11 months later...
I'm not sure why you would get that error unless the script does not have execute permissions.

 

However if you are wanting to backup a MySQL database I would recommend using dbsender and then follow the directions in this thread to configure it.

 

 

I realize this thread is a year old but I wanted to ask if there have been any 'advancements' in the last year or is using dbsender still the recommended method to backup a MySQL database?

 

Thanks.

Link to comment
Share on other sites

I am working on installing dbsender but there are some things I don't understand.

 

The dbsender instructions say:

 

If running from shell, put this above the <?php "#! /usr/bin/php -q" without the quotes!!!

What is "shell"?

 

Also, how do I chown the directory this script resides in to the same user or group your webserver runs in.

 

Which directory do you recommend I put this?

Link to comment
Share on other sites

What is "shell"?

 

Also, how do I chown the directory this script resides in to the same user or group your webserver runs in.

 

Which directory do you recommend I put this?

 

For your purpose, running from a shell is the same as running it from cron. As opposed to running it by putting it on your website and hitting a URL.

 

So you will want the #!/usr/bin/php -q as the first line of your file (no blank lines before it), which tells the script where to find the PHP interpreter when the script is executed.

 

If you are running it as cron, you shouldn't have to chown the directory or files, as it'll run as your account, not the webserver account. Location of the script should be anywhere in your account that isn't under public_html directory tree.

Link to comment
Share on other sites

If you are running it as cron, you shouldn't have to chown the directory or files, as it'll run as your account, not the webserver account. Location of the script should be anywhere in your account that isn't under public_html directory tree.

 

Thanks for helping.

 

Is the location you mentioned above the place to put the script so that it is not accessible to others or is that where it needs to be to function/run properly? Just curious about that.

Link to comment
Share on other sites

If the script is asking:

// Configure the path that this script resides on your server.

 

$savepath = "/www/htdocs/dbsender"; // Full path to this directory. Do not use trailing slash!

 

and I have put the file directly in the ftp.sitename.com directory. What would my path be?

Link to comment
Share on other sites

I believe I have made the proper entries in the .php file and uploaded it.

 

Now, do I need to set up a cron job via cPanel or do I contact TCH support as the following quote seems to say?

 

This script is meant to be setup on a crontab and run on a weekly basis

You will have to contact your system administrator to setup a cron tab for this script

Here's an example crontab:

 

0 0-23 * * * php /path/to/thisdirectory/dbsender.php > dev/null

Link to comment
Share on other sites

I changed permissions of dbsender folder to 770, as specified in the TCH guide.

 

Would I need to change permissions of the file itself? It is presently: 644

 

 

Also, the instructions that came with dbsender says:

 

You must chown the directory this script resides in to the same user or group your webserver runs

in, or CHMOD it to writable. I do not recommend chmod 777 but it's a quick solution. If you can setup

a cron, you can probably chown your directory!

Would it have been better for me to CHOWN the directory instead of CHMOD it to writable?

 

Thanksl.

Link to comment
Share on other sites

If anything is wrong with the cron job I think you will find a error message in the cpanelusernames mailbox (ie default adress).

Please note that I don´t know all the reasons it may send a error message for (wrong path, wrong permissions etc), but its worth looking if there is a message.

Link to comment
Share on other sites

  • 1 month later...

I have been using dbsender and it looks like it has been emailing the database to me daily (as I had set up in cpanel).

 

But I just noticed that I am getting a daily email from: "Cron Daemon" <root@server300.snhdns.com>

 

Subject: Cron <myusername@server300> /usr/bin/php -q /home/myusername/dbsender/dbsender.php

 

sh: ncftpput: command not found<h4><center>Database backup created and sent! File name/home/myusername/dbsender/myusername_local-051107-0200am_sql.tar.gz</center></h4><h4><center>/home/myusername/dbsender/myusername_local-051107-0200am_sql.tar.gzWas created and uploaded to your FTP server!</center></h4>

 

Is this an error of some sort?

Link to comment
Share on other sites

  • 4 weeks later...

I just noticed that my 'default' email account is receiving an email each time that the cron backup is processed.

 

From:Cron Daemon

Subject: Cron <mysite@serverXXX> /usr/bin/php -q /home/myusername/dbsender/dbsender.php

<h4><center>Database backup created and sent! File name

/home/myusername/dbsender/myusername_directory-060807-0200am_sql.tar.gz</center></h4>

 

 

I have the actual cron backup file sent to another email address.

 

Is there a way to have the Cron Daemon email sent to another email address or to have it not sent at all?

 

Thanks.

Link to comment
Share on other sites

In the dbsender script find this section:

 

// Send the message

$ok = @mail($to, $subject, $message, $headers);

if ($ok) {

echo "

Database backup created and sent! File name $filename2

";

} else {

echo "

Mail could not be sent. Sorry!

";

}

 

And change it to this:

 

// Send the message

$ok = @mail($to, $subject, $message, $headers);

if (!$ok) {

echo "

Mail could not be sent. Sorry!

";

}

 

Or add an email address to send it too. Just changing it to send a message on failure would be sufficient. If you don't receive the backup you can check your default account email.

Link to comment
Share on other sites

1) The changes that you show in your quote will stop any email from being sent, right?

 

2) Where do I add the email address to send the email to?

 

3) How would I change it to only have a message sent if there was a failure?

Link to comment
Share on other sites

2. $ok = @mail($to, $subject, $message, $headers); <-- change $to to a valid email address

 

I'm not smart enough to figure out how change $to a valid email address.

 

My latest attempt was:

2. $ok = @mail(myemail@host.com, $subject, $message, $headers);

 

But I've been getting this message from Cron Daemon in my default email:

 

<br />

<b>Parse error</b>: syntax error, unexpected '@' in

<b>/home/username/dbsender/dbsender.php</b> on line <b>115</b><br />

Link to comment
Share on other sites

In the dbsender script find this section:

 

// Send the message

$ok = @mail($to, $subject, $message, $headers);

if ($ok) {

echo "

Database backup created and sent! File name $filename2

";

} else {

echo "

Mail could not be sent. Sorry!

";

}

 

And change it to this:

 

// Send the message

$ok = @mail($to, $subject, $message, $headers);

if (!$ok) {

echo "

Mail could not be sent. Sorry!

";

}

 

Just do the above and you will stop recieving the emails.

Link to comment
Share on other sites

I like the option that you earlier mentioned:

 

Or add an email address to send it too. Just changing it to send a message on failure would be sufficient. If you don't receive the backup you can check your default account email.

 

I'm trying to figure out how to add the email address.

Link to comment
Share on other sites

I tried escaping the email address but ended up getting an email from Cron Daemon. Here is the message:

 

 

 

<br />

<b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in

<b>/home/username/dbsender/dbsender.php</b> on line <b>115</b><br />

<br />

<b>Parse error</b>: syntax error, unexpected '@' in

<b>/home/username/dbsender/dbsender.php</b> on line <b>115</b><br />

 

I entered my email address, in dbsender.php, in the format: you\@yourdomain.ext

 

Did I do something wrong?

Link to comment
Share on other sites

The problem you have is you are seeing output that the script is producing. Since the script is being run by cron there is no output device as if you were executing the script from your web browser.

 

I have modified my dbsender scripts as explained in this post.

 

If you want to stop those mail sent messages from going to your default account you will have to change your script.

Link to comment
Share on other sites

Is that all you have tried? I've given you three different things to do. One of them should work for you.

 

 

Above I've mentioned that I've tried 2 or 3 methods. But I get a Cron Daemon email error each time.

 

I have not yet tried:

or just above the $ok line add a line

 

 

>$to = you@yourdomain.ext;

 

I will try that next.

Link to comment
Share on other sites

It's not going to work, see my post above yours.

 

The problem you have is you are seeing output that the script is producing. Since the script is being run by cron there is no output device as if you were executing the script from your web browser.

 

I have modified my dbsender scripts as explained in this post.

 

If you want to stop those mail sent messages from going to your default account you will have to change your script.

Link to comment
Share on other sites

  • 7 months later...

I found:

With Gmail, you can send and receive messages up to 20 megabytes (MB) in size.

 

Where can I read more about TCH's backup policy? I don't have access to a domain hosted email account on a server other than the one I am trying to back up so I can't have the file sent there that at this time.

 

Also, I believe that TCH support told me that 34MB was the largest file I could send from my domain and I might get to that limit soon anyway.

Link to comment
Share on other sites

From - Not that I know about.

To - Only the limit you have set on the mail account I belive.

 

Also, I saw earlier in the thread that you were asking how big attachments gmail allows, I believe it´s 20 mb.

 

How do I check the size of my mysql database?

 

My website is over 20MB but I don't think my mysql db is that large.

Link to comment
Share on other sites

How do I check the size of my mysql database?

 

My website is over 20MB but I don't think my mysql db is that large.

 

Checking the size of the database would be a waste of time since dbsender does not send you the database. It sends you a compressed dump of the database which is typically much smaller than the database itself.

 

Making a backup and downloading it to your machine will give you an approximate size of the file dbsender will send. But remember, the file will be encoded for sending and will end up being larger than the compressed file you download.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...