Last active
August 29, 2015 14:09
-
-
Save cjsewell/64b3494c95e54d97305a to your computer and use it in GitHub Desktop.
Simple php script to grab a copy of a site and database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('display_errors', 'On'); | |
$siteArchive = $_SERVER['DOCUMENT_ROOT'] . "/site.tar.gz"; | |
$dbDump = $_SERVER['DOCUMENT_ROOT'] . "/dump.sql"; | |
$outputeArchive = array(); | |
$return_varArchive = 99; | |
$outputDump = array(); | |
$return_varDump = 99; | |
error_reporting(E_ALL); | |
if (isset($_GET['dump'])) { | |
echo "Dumping "; | |
$resDump = exec("mysqldump --user=DBUSER --password=DBPASS --host=DBHOST DBNAME > " . $dbDump . " 2>&1", $outputDump, $return_varDump); | |
echo '<pre class="debug"> "$output"' . PHP_EOL . print_r($outputDump, true) . PHP_EOL . '</pre>'; | |
echo '<pre class="debug"> "$return_var"' . PHP_EOL . print_r($return_varDump, true) . PHP_EOL . '</pre>'; | |
echo '<pre class="debug"> "$res"' . PHP_EOL . print_r($resDump, true) . PHP_EOL . '</pre>'; | |
$resArchive = exec("cd " . $_SERVER['DOCUMENT_ROOT'] . " && tar -czf " . $siteArchive . " . 2>&1", $outputeArchive, $return_varArchive); | |
echo '<pre class="debug"> "$output"' . PHP_EOL . print_r($outputeArchive, true) . PHP_EOL . '</pre>'; | |
echo '<pre class="debug"> "$return_var"' . PHP_EOL . print_r($return_varArchive, true) . PHP_EOL . '</pre>'; | |
echo '<pre class="debug"> "$res"' . PHP_EOL . print_r($resArchive, true) . PHP_EOL . '</pre>'; | |
echo "Done"; | |
} | |
if (isset($_GET['cleanup'])) { | |
echo "Remove " . $siteArchive; | |
if (unlink($siteArchive)) { | |
echo " Done"; | |
} else { | |
echo " Failed"; | |
} | |
echo "</br>"; | |
echo "Remove " . $dbDump; | |
if (unlink($dbDump)) { | |
echo " Done"; | |
} else { | |
echo " Failed"; | |
} | |
echo "</br>"; | |
echo "Remove " . __FILE__; | |
if (unlink(__FILE__)) { | |
echo " Done"; | |
} else { | |
echo " Failed"; | |
} | |
echo "</br>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment