newznab – Delete all releases

I realised that an installation of newznab that I’d been playing with and forgotten about has eaten up a substantial amount of HDD space and wanted to delete all the releases. Unfortunately, there’s not an easy way to do this. I managed to work out two ways to do it.

The easier way

Inside your installation, in the misc/testing folder there will be a file called deletereleases.php.

Around line 65, before $rel = $db->query($sql);, add the following code:

//
// [9] delete all releases
//
$sql = "select ID from releases LIMIT 5000";

Save the file, then run:

php deleterelease.php

This could take a while as it fetches 5000 ID’s at a time and iterates over them, deleting releases as it goes. You can experiment with a number higher or lower than 5000 as you see fit. You’ll need to run the script multiple times.

The faster way

Personally, I didn’t want to wait that long. If you’re comfortable deleting files on disk and truncating database tables, this is the solution for you:

I’m going to assume that you’re in the root folder of your newznab installation when providing commands to run. (This is the one that contains INSTALL.txt, db, misc, nzbfiles and www)

First, delete all of the old nzb files:

$(cd nzbfiles; for i in `ls`; do rm $i/*.nzb.gz; done)

Then delete all the old covers:

$(cd www/covers; for i in `ls`; do rm $i/*.jpg; done)

Finally, truncate all of the old tables.

mysql -u user -p db_name

TRUNCATE TABLE releaseaudio;
TRUNCATE TABLE releasecomment;
TRUNCATE TABLE releaseextrafull;
TRUNCATE TABLE releasefiles;
TRUNCATE TABLE releasenfo;
TRUNCATE TABLE releases;
TRUNCATE TABLE releasesubs;
TRUNCATE TABLE releasevideo;
TRUNCATE TABLE binaries;
TRUNCATE TABLE bookinfo;
TRUNCATE TABLE usercart;
TRUNCATE TABLE userdownloads;
TRUNCATE TABLE parts;
TRUNCATE TABLE tvrage;
TRUNCATE TABLE episodeinfo;
TRUNCATE TABLE animetitles;
TRUNCATE TABLE thetvdb;

Then you’re done. Here’s the result for me:

Before:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       60G   60G  970M  99% /

After:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       60G  1.1G   59G   2% /

Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter

Thoughts on this post

Just James 2014-01-15

Thanks for this. Saved me a lot of time and effort figuring out how to do this myself. I reset the groups with:
UPDATE groups SET first_record = 0;
UPDATE groups SET first_record_postdate = NULL;
UPDATE groups SET last_record = 0;
UPDATE groups SET last_record_postdate = NULL;

[…] Je nachdem, wieviel Space man zur Verfügung hat auf der Platte, kann es durchaus sein, dass Newznab einem irgendwann die komplette Platte weggefressen hat. Dann sollte man einen Cleanup machen. Nach langer Suche bin ich auf folgenden Beitrag gestossen: http://michaelheap.com/newznab-delete-all-releases/ […]

Leave a comment?

Leave a Reply