[NEWZNAB][LINUX] simple automated backfill day-by-day script
Posted: January 30th, 2013, 8:39 am
hey folks,
just wrote a backfill script that is going day-by-day for either one or all active groups.
Let me know, if you use it or have any suggestions.
Agent
just wrote a backfill script that is going day-by-day for either one or all active groups.
Code: Select all
<?php
// This script is doing automated backfills and release updates day-by-day for either one or all groups.
// After every 5 backfills, it will perform a database optimisation, can be changed on line 59.
// Every 25 backfills, it will perform a binaries update, so you keep relatively up to date.
// I would recommend not to use "php runbackfill.php &" or if you do, write down the PID.
// This selects the group to backfill
echo "Please enter the Group you want to backfill, leave blank for all: ";
$group = chop(fgets(STDIN));
// The Date till the backfill goes
while(empty($end)) {
echo "[REQUIRED] Till when do you want to backfill (e.g. 2011-12-31): ";
$end = strtotime(chop(fgets(STDIN)));
}
// The MySQL-Password, if entered on line 39 please delete or comment out the whole "while-loop"
while(empty($mysql_password)) {
echo "[REQUIRED] Please enter your MySQL-Password: ";
$mysql_password = chop(fgets(STDIN));
}
// Checks whether all or one single group
if ($group == false) {
$db_groups = "active='1'";
}
else {
$db_groups = "name='".$group."'";
}
// Please adjust, if necessary
$path_to_optimise_db = "/usr/bin/php /var/www/newznab/misc/update_scripts/optimise_db.php";
$path_to_backfill_date = "/usr/bin/php /var/www/newznab/misc/update_scripts/backfill_date.php";
$path_to_update_releases = "/usr/bin/php /var/www/newznab/misc/update_scripts/update_releases.php";
$path_to_update_binaries = "/usr/bin/php /var/www/newznab/misc/update_scripts/update_binaries.php";
// The databasequery, please adjust to your settings
$database = mysql_connect("localhost", "root", "".$mysql_password."") or die ("Can not connect, wrong password?");
mysql_select_db("newznab") or die ("Database not found");
//=========== No further adjustments needed ============
$first_record_postdate = mysql_query("SELECT name, first_record_postdate FROM groups WHERE ".$db_groups."");
while($row = mysql_fetch_object($first_record_postdate))
{
$name = $row->name;
$first_date = $row->first_record_postdate;
$start = strtotime($first_date);
$i = 1;
$j = 1;
while ($start >= $end) {
$day = date("Y-m-d", $start);
$update = "".$path_to_backfill_date." ".$day." ".$name." && ".$path_to_update_releases."";
passthru($update, $return_update);
echo $return_update;
$start = ($start - 86400);
$i++;
if ($i == 5) {
passthru($path_to_optimise_db, $return_optimise);
echo $return_optimise;
$i = 1;
$j++;
if ($j == 5) {
passthru("".$path_to_update_binaries." && ".$path_to_update_releases."", $return_binaries);
echo $return_binaries;
$j = 1;
}
}
}
}
mysql_close($database);
exit();
?>
Agent