SitePoint Sponsor

User Tag List

Page 3 of 4 FirstFirst 1234 LastLast
Results 51 to 75 of 81
  1. #51
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    crontab won't have any problems with .htaccess, it doesn't affect any internal file access.

  2. #52
    SitePoint Member TW.'s Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I guess I have more obsticles to set this up with cron.

    When I tried to run it with cron I got these errors:
    Code:
    /home/USER/domains/mysite.com/public_html/mysql_backup.php: 
    ?php: No such file or directory
    /home/USER/domains/mysite.com/public_html/mysql_backup.php: 
    //: is a directory
    /home/USER/domains/mysite.com/public_html/mysql_backup.php:
    //: is a directory
    /home/USER/domains/mysite.com/public_html/mysql_backup.php: 
    line 4: syntax error near unexpected token `include("'
    /home/USER/domains/mysite.com/public_html/mysql_backup.php:
    line 4: `include("/home/USER/domains/mysql_backup/user.php" ); '
    
    .
    I don't know why I did it but I striped all the commented lines out of file and left just the php code and got this error:
    Code:
    /bin/sh: /home/USER/domains/mysite.com/public_html/mysql_backup.php:
    Permission denied
    But now that I have done it and have looked over the other error I wonder why I didn't get the "?php: No such file or directory" error.

    Any Ideas or do you think my server isn't allowing the automation of php scripts? It says in my doucumentation that cron will call a cgi script but it doesn't say anything specific about php.

    Ah the life of a wannabe webmaster

    TW
    Last edited by TW.; Oct 29, 2003 at 07:48.

  3. #53
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Usually you set up your cron jobs through a control panel on your hosting account. You simply specify the path where the file you want to run is located at and that should be it.

    You shouldn't be getting any errors about cgi since you are running a php script not a cgi script. Please provide more details of how you are setting up your cron jobs.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  4. #54
    SitePoint Member TW.'s Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Toly
    Usually you set up your cron jobs through a control panel on your hosting account. You simply specify the path where the file you want to run is located at and that should be it.

    You shouldn't be getting any errors about cgi since you are running a php script not a cgi script. Please provide more details of how you are setting up your cron jobs.
    I did exactly that. I set it up through my DA panel to run "mysql_backup.php" which is located at "/home/USER/domains/mysite.com/public_html/mysql_backup.php"
    Then I get the above errors sent to my e-mail.

    I get no cgi errors I was just stateing that I went into my documentation for my admin panel and under "Cron Jobs" it states that a cgi script can be run, but it says nothing specific about PHP.

    The errors above seem to me that my server doesn't allow php thru cron because of the first 2 lines of error:
    Code:
    /home/USER/domains/mysite.com/public_html/mysql_backup.php:
    ?php: No such file or directory
    I have sent a e-mail to my server admin for more info on my cron privileges and what can and can not be run from cron.

    TW

  5. #55
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change the backup script so it stores the dbase backup to your server instead of sending it to you by email, just as a test.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  6. #56
    SitePoint Member TW.'s Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Toly
    Change the backup script so it stores the dbase backup to your server instead of sending it to you by email, just as a test.
    I apreciate the responce Toly but I think maybe you have me confused with someone else you are helping, but I don't have it going to an e-mail.
    I have it set to put the back_up file in a folder on my server and it works fine when called though the browser just not with cron!
    If I can get it to work I want to send it to e-mail or ftp it but that is a later issue.

    TW

  7. #57
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TW.
    I apreciate the responce Toly but I think maybe you have me confused with someone else you are helping, but I don't have it going to an e-mail.
    Lol... I'm not confused (haven't gotten to that age yet), I just thought that you already have it set up so it will go to your email since you wrote "Then I get the above errors sent to my e-mail.". I thought that instead of an email with the backup file, you'd get an email with errors or something.

    Any answer from your host yet?
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  8. #58
    SitePoint Member TW.'s Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hahahaha now I know where you got the idea that I had it sent to e-mail and it was my fault you were mislead sorry so sorry but...
    These e-mail's I refered to came from the cron damen on my server letting me know that the scheduled event's did not execute.

    No word yet from host they are kinda slow I guess that's the swap off for cheap
    I'll post what they say when they do

    Thanx so much for your time

    TW

  9. #59
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    TW

    Try entering your cron command like

    Code:
    php -q /home/USER/domains/mysite.com/public_html/mysql_backup.php

  10. #60
    SitePoint Member TW.'s Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I finally got word back from server admin and they stated that it couldn't be done but they would see if they could add that funtionability

    But then I got a responce in their forums from a mod that told me to enter the command like this:
    Code:
    /usr/local/bin/php /home/USER/domains/mysql_backup/mysql_backup.php
    And it worked perfectly
    Plus it is above my web directory so no one can mess with it and crash my server and that is always good.

    Thank you all so much for your time and patience with me

    Now all I have left is to add FTP and/or e-mail functions to the script and I will be all set

    Thanx again
    TW

  11. #61
    SitePoint Member TW.'s Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I tried my hand at figuring out FTP functions in php and failed

    This is the code I added to the bottom of the script:
    Code:
        $ftp_server = "ftp.Mysite.com";
        $ftp_user = "Myusername";
        $ftp_pass = "Mypass";
        $source_file = $backupas
        $destination_file = /home/USER/domains/mysql_backup/$backupas
    // set up a connection or die
        $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
    // try to login
    if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
        echo "Connected as $ftp_user@$ftp_server\n";
    } else {
        echo "Couldn't connect as $ftp_user\n";
    }
    // file upload
        $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
    // Close FTP connection
    ftp_quit($conn_id);
    I added that code just before the exit command in the original file.

    It not only didn't FTP the file it made the whole script quit working

    The cron damen sent this error:
    Code:
    PHP Parse error:  parse error in /home/USER/domains/mysql_backup/mysql_backup.php
    on line 22
    Line 22 is
    Code:
    $destination_file = /home/USER/domains/mysql_backup/$backupas
    From this I am guessing that I need to name the file to be uploaded but how can I when the name of the file will change daily?

    I have the FTP set to a different account on the same server for testing. If I get it to work I will reset it to FTP to a tripod account or some other free service.

    Did I miss something or put the code in the wrong place?

    Well I have time to figure it out at least I have the script making me a backup every morning now and I can physically download it to my HD untill I can get it to work so the worse thing that could happen is I will be 2 days behind instead of 1 if the server crashes before I get the daily file downloaded!
    I can live with that but if you can help me set up FTP it would be so much better.

    I want to thank you all 1 more time for your help

    TW

  12. #62
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $destination_file "/home/USER/domains/mysql_backup/$backupas"

  13. #63
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This line needs a semi-colon too...

    PHP Code:
    $source_file $backupas
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  14. #64
    SitePoint Member TW.'s Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I have added the 2 semicolons I missed and the quotes on the destination file variable and it started working again.
    But it didn't ftp the file to my other account.
    And it doesn't generate any errors

    Darn and I thought that only 3 errors in my first actual php script writeing.

    I think that the problem may lie in the source file name.

    What if I take the date variable out of the original file so I can have a constant file name to define then add the date on the FTP part of the script?
    Do you think that would work?

    TW

  15. #65
    SitePoint Member TW.'s Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know you guys are probably getting tired of hearing from me but here we go again.
    OK I am getting close I think. This is the file I have at the moment:
    Code:
    <?php
    // Include your user and password $user $pass
    // outside the public folder
    include("/home/USER/domains/mysql_backup/user.php" ); 
    // Mysql Database Information:
        $database = 'My_database';   // name of the database.
        $username = $user; //  username with access to database.
        $password = $pass; //  password for username.
        $date = date("dmy" );
    // Database Backup Filename & Location
        $backupto = '/home/USER/domains/mysql_backup/backups';  
    // absolute path to folder containing database - no trailing slash.
        $backupas = $database . $date . '.sql' . '.gz';
    // Perform backup
        $backupcommand = "mysqldump -u$username -p$password $database | gzip          
     >$backupto/$backupas";
        passthru ("$backupcommand", $error);
        $ftp_server = "ftp.Mysite.net";
        $ftp_user = "Myftp_username";
        $ftp_pass = "MyPass";
        $source_file = $backupas;
        $destination_file = "/home/USER/domains/mysql_backup/$backupas";
    // set up a connection or die
        $conn_id = ftp_connect($ftp_server) or die
    ("Couldn't connect to $ftp_server");
    // try to login
    if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
        echo "Connected as $ftp_user@$ftp_server\n";
    } else {
        echo "Couldn't connect as $ftp_user\n";
    }
    // file upload
        $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
    // check upload status
    if (!$upload) { 
            echo "FTP upload has failed!";
        } else {
            echo "Uploaded $source_file to $ftp_server as $destination_file";
        }
    // Close FTP connection
    ftp_quit($conn_id);
        if($error) {
        echo ("Problem: $error\n" );
     exit;
    }
    ?>
    With this file I ge the following message:
    Code:
    Connected as USER@ftp.Mysite.net FTP upload has failed!
    So it is writing my backup to local server and it is connecting via ftp but the upload is failing.
    I tried takeing date out of backup and adding it to the ftp part by defining the source file like this:
    Code:
    $source_file = "/home/USER/domains/mysql_backup/backups/My_database.sql.gz";
    and the destination file like this:
    Code:
    $destination_file = "/home/USER/domains/mysql_backup/$date . My_database.sql.gz";
    but I got the same message!

    I wonder if I would be better off spliting this into 2 seperate scripts and have them run say 5 minutes apart?

    But wait I have an Idea I think in this situation I should define destination file like this:
    Code:
    $destination_file = "/home/USER/domains/mysql_backup/$date . $source_file";
    I'll go try that and see what happens.

    TW

  16. #66
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Uruguay
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    I'm using this script:
    <?php
    // Include your user and password $user $pass
    // outside the public folder
    include("db_login.php");
    // Mysql Database Information:
    $database = 'name_of_db'; // name of the database.
    $username = $user; // username with access to database.
    $password = $pass; // password for username.
    // Database Backup Filename & Location
    $backupto = '/path/to/save/databases'; // absolute path to folder containing database - no trailing slash.
    $backupas = $database . '.sql' . '.gz';
    // Perform backup
    $backupcommand = "mysqldump -u$username -p$password $database | gzip >$backupto/$backupas";
    passthru ("$backupcommand", $error);
    if($error) {
    echo ("Problem: $error\n"); exit;
    }
    ?>

    and works fine.

    But how can I use it with CPANEL and cron jobs?

    If I use this command: php -f /home/mysite/public_html/backup/backup.php

    the cron job sends me this error: mysqldump: Got error: 1044: Access denied for user: '@localhost' to database 'name_database' when selecting the database

    If someone can help me...

    Thanks!
    Martin

  17. #67
    SitePoint Member TW.'s Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when using a php script on Linux you need to add the path to php then a space before the path to the script.
    Your cron job should look something like this.
    Code:
    /usr/local/bin/php /home/username/public_html/path/to/backup.php

    Hope that helps ya
    TW

  18. #68
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Uruguay
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks TW, but how can I know the path to php in my server using CPANEL or FTP access?

    Thanks
    Martin

  19. #69
    SitePoint Member TW.'s Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well the above is where it is on my redhat server.

    It could be any of the following on different flavors of Linux.

    /bin/php
    /usr/bin/php
    /sbin/php
    /usr/sbin/php
    /usr/local/bin/php
    /usr/local/sbin/php

    You could e-mail your host for the info or just try them till it works, that's what I did.

    If you set your cron up to execute every 5 minutes or so it will e-mail you an error report if something is wrong.
    Check the report it will tell you what is wrong. Then fix whatever is wrong eg path to php, errors in the script ect... and sit back and wait for next time it executes. If you get no cron error report then you know it worked, and you can check to make sure the back up has been made then reset the cron time for daily, weekly, or whatever you need.



    TW

  20. #70
    SitePoint Guru gavwvin's Avatar
    Join Date
    Nov 2004
    Location
    Cornwall, UK
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was just about to post asking how to do this, then I found this thread. unfortunately I'm having trouble getting the script to work. When I echo $error I get "127", nothing happens I can't find the file in the folder I set it to. When I echo the command it looks like this (specifics replaced of course)

    mysqldump -u user -p password database >/home/httpd/sitename/httpsdocs/somefolder/database.sql

    (I know I shouldn't be saving it in a folder under the root, I'm just trying to get it working at the moment) The folder has permissions of 777. Any ideas?

  21. #71
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Uruguay
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks TW.

    I probe and some path gives me the following error:
    /usr/local/sbin/php: No such file or directory for example, I think that this error is becuase the path is incorrect.

    and other give me the error: mysqldump: Got error: 1044: Access denied for user: '@localhost' to database 'name_database' when selecting the database

    If someone can help me...

    Thanks
    Martin

  22. #72
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gavwvin
    When I echo $error I get "127", nothing happens I can't find the file in the folder I set it to.
    According to what I read, 127 is a command not found error. Make sure that the full path you are using is correct.

    Quote Originally Posted by martinacastro
    and other give me the error: mysqldump: Got error: 1044: Access denied for user: '@localhost' to database 'name_database' when selecting the database
    That means that the user does not have privileges to access that database. When you create a user for one or more databases, you have to grant that user privileges to those databases first.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  23. #73
    SitePoint Evangelist lance_vincent's Avatar
    Join Date
    Aug 2004
    Location
    philippines
    Posts
    574
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh before i forgot, im also having that problem 1 error, im not on linux so i cannot apply that chmod solution you presented. im on winxp, and im using mysql4.0 at home. i tried tp write to c:\, the .sql file was written, but nothing is written. tried writing to c:\mysql\data\databasename\ also the same problem.

    what am i doing wrong? or am i stupid!! hope you dont look at me like a total idiot!!

    hope youll welcome me to the club!!

  24. #74
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lance_vincent
    do you think such would work, i would like to try it now, but im facing a new problem, actually, i think im having a badluck day!! my query broweser and administrator doesnt work anymore after i uninstalled mysql4 for mysql5. i tried reinstalling the two, but nithing. any hint on this one?
    I'm not sure what could be the problem. I have only installed MySQL once or twice on a pc.

    Quote Originally Posted by lance_vincent
    oh before i forgot, im also having that problem 1 error, im not on linux so i cannot apply that chmod solution you presented. im on winxp, and im using mysql4.0 at home. i tried tp write to c:\, the .sql file was written, but nothing is written. tried writing to c:\mysql\data\databasename\ also the same problem.
    First of all, no one is an idiot or stupid just because he/she does not know something, so relax and stop calling yourself that.

    Anyways, like I said above, I don't work php and mysql in windows. I do have php and apache set up on my winxp machine, but only to test small php scripts. I don't know much about permissions and paths in windows since I do all of that on my linux server.

    If you are still having problems, I can install mysql on my pc and see if I can run the script.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  25. #75
    SitePoint Evangelist lance_vincent's Avatar
    Join Date
    Aug 2004
    Location
    philippines
    Posts
    574
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now im really dead, ive waited long for that reply toly. yes if you have to, please help me. i have uploaded my application but the backup is not working.

    i have something to inform anyway, ive tried that chmod, give it 777, but the problem now is not 1, its 127 ?!$%!@

    what should i do.

    you could pay a visit to http://rtolms.epinoy.com/system/admi...ementpanel.php
    if it ask for a username and password, use root and sql. but dont tell it to anyone, im going to edit that combination after march 22, so i could maintain my security. ive just finished defending that and pass the test. tahnk you guys!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •