therealwesfoster Posted August 18, 2008 Share Posted August 18, 2008 I'm confused on where to turn, so phpfreaks was my first choice for this. Hopefully ya'll can help. There are a few sites that dump their database for me and make it available for me to download (in .tar.gz format). I'm needing help creating a PHP script I can setup with a CRON job that will download the database dump, extract it (if necessary), and update my database with it's information. How can something like this be achieved? Wes Quote Link to comment https://forums.phpfreaks.com/topic/120210-php-download-extract-and-install/ Share on other sites More sharing options...
trq Posted August 18, 2008 Share Posted August 18, 2008 I wouldn't even bother using php for such a task. A simple bash script makes the job so much easier. !#/bin/bash wget http://domain.com/dump.tar.gz gzcat dump.tar.gz | tar xvf - mysql -uUSER -pPASSWORD DATABASE < *.sql Will need some error handling / tweaking but should suffice. Quote Link to comment https://forums.phpfreaks.com/topic/120210-php-download-extract-and-install/#findComment-619283 Share on other sites More sharing options...
JonnoTheDev Posted August 18, 2008 Share Posted August 18, 2008 When you say dump their database - are they giving you the sql or are they giving you the database in CSV format. If they are giving you the sql then this is easy. Use CURL to download the sql.tar.gz file. Extract the tar.gz file: tar -xvzf sql.tar.gz Use mysql to restore the file: mysql -u -p databaseName < pathtosql So your program to run from a cron can be a simple file that contains: php /home/user/getDBFile.php tar -xvzf sql.tar.gz mysql -u -p databaseName < pathtosql We save this file as dbupdate Then in your crontab: * * * * * /path/dbupdate Quote Link to comment https://forums.phpfreaks.com/topic/120210-php-download-extract-and-install/#findComment-619295 Share on other sites More sharing options...
JonnoTheDev Posted August 18, 2008 Share Posted August 18, 2008 thorpe's suggestion will work using wget as long as the site giving you the db dump doesnt require any authentication or a form submitting to retrieve the file. Then you would need CURL to do this. Quote Link to comment https://forums.phpfreaks.com/topic/120210-php-download-extract-and-install/#findComment-619299 Share on other sites More sharing options...
trq Posted August 18, 2008 Share Posted August 18, 2008 wget supports both a username and password option for basic http authentication. Quote Link to comment https://forums.phpfreaks.com/topic/120210-php-download-extract-and-install/#findComment-619303 Share on other sites More sharing options...
therealwesfoster Posted August 18, 2008 Author Share Posted August 18, 2008 Thanks for the replies, and yes, the file that is dumped is a csv file. I wouldn't even bother using php for such a task. A simple bash script makes the job so much easier. !#/bin/bash wget http://domain.com/dump.tar.gz gzcat dump.tar.gz | tar xvf - mysql -uUSER -pPASSWORD DATABASE < *.sql Will need some error handling / tweaking but should suffice. I'm willing to do whatever Would this be a perl script? Or what? I'm just a php pro, none of this other junk Wes Quote Link to comment https://forums.phpfreaks.com/topic/120210-php-download-extract-and-install/#findComment-619442 Share on other sites More sharing options...
trq Posted August 18, 2008 Share Posted August 18, 2008 Would this be a perl script? Or what? I'm just a php pro, none of this other junk No, its a Bash script. Quote Link to comment https://forums.phpfreaks.com/topic/120210-php-download-extract-and-install/#findComment-619559 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.