Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.