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

Got a program that plays well with SABnzbd? Share it here!
Post Reply
Posts: 3
Joined: January 30th, 2013, 8:36 am

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

Post by agentclark » 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.

Code: Select all

// 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);
	if ($i == 5) {
		passthru($path_to_optimise_db, $return_optimise);
		echo $return_optimise;
		$i = 1;
		if ($j == 5) {
			passthru("".$path_to_update_binaries." && ".$path_to_update_releases."", $return_binaries);
			echo $return_binaries;
			$j = 1;

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

Posts: 2
Joined: January 9th, 2012, 2:31 pm

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

Post by guru-69 » April 1st, 2013, 5:20 pm

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.

Posts: 1
Joined: August 15th, 2013, 1:48 am

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

Post by kpo967 » August 15th, 2013, 1:52 am

Should I execute this script with "php {script name}.php"? Or is there a different way?

Post Reply