Page 1 of 1

[NEWZNAB][LINUX] simple automated backfill day-by-day script

Posted: January 30th, 2013, 8:39 am
by agentclark
hey folks,

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();
?>

Let me know, if you use it or have any suggestions.
Agent

Re: [NEWZNAB][LINUX] simple automated backfill day-by-day sc

Posted: April 1st, 2013, 5:20 pm
by guru-69
Great script! Thanks for sharing this. I totally underestimated how long it would take to go back 90 days on one group, but worked perfectly to backfill a day at time and keep my other groups up-to-date. About halfway through I started to notice this error, but I doubt its from your script:

AniDB : Updating animetitles.PHP Warning: gzopen(http://anidb.net/api/animetitles.dat.gz): failed to open stream: Connection timed out in /var/www/newznab/www/lib/anidb.php on line 43

I don't care for anime anyways ;D

I will create a DB backup, then run your script again on all my groups.

Re: [NEWZNAB][LINUX] simple automated backfill day-by-day sc

Posted: August 15th, 2013, 1:52 am
by kpo967
Should I execute this script with "php {script name}.php"? Or is there a different way?