Jump to content

PHP download, extract, and install


therealwesfoster

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/120210-php-download-extract-and-install/
Share on other sites

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.

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

 

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.