Add shell script to delete garbage files and discarded chunks

This commit is contained in:
Kijin Sung 2017-01-27 15:15:32 +09:00
parent 054191a69d
commit b767ff7a94
3 changed files with 70 additions and 1 deletions

View file

@ -18,6 +18,74 @@ $days = 10;
// Initialize the exit status.
$exit_status = 0;
// Initialize objects.
$oDB = DB::getInstance();
$oFileController = getController('file');
// Find and delete files where isvalid = N.
$args = new stdClass;
$args->isvalid = 'N';
$args->list_count = 50;
$args->regdate_before = date('YmdHis', time() - ($days * 86400));
while (true)
{
$output = executeQueryArray('file.getFileList', $args);
if ($output->toBool())
{
if ($output->data)
{
$oDB->begin();
foreach ($output->data as $file_info)
{
$oFileController->deleteFile($file_info->file_srl);
}
$oDB->commit();
}
else
{
break;
}
}
else
{
echo "Error while deleting garbage files older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 11;
break;
}
}
if ($exit_status == 0)
{
echo "Successfully deleted all garbage files older than $days days.\n";
}
// Find and delete temporary chunks.
$dirname = RX_BASEDIR . 'files/attach/chunks';
$threshold = time() - ($days * 86400);
$chunks = Rhymix\Framework\Storage::readDirectory($dirname);
if ($chunks)
{
foreach ($chunks as $chunk)
{
if (@filemtime($chunk) < $threshold)
{
$result = Rhymix\Framework\Storage::delete($chunk);
if (!$result)
{
$exit_status = 12;
}
}
}
}
if ($exit_status == 0)
{
echo "Successfully deleted aborted file chunks older than $days days.\n";
}
else
{
echo "Error while deleting aborted file chunks older than $days days.\n";
}
// Set the exit status if there were any errors.
if ($exit_status != 0)
{

View file

@ -27,7 +27,7 @@ else
{
echo "Error while deleting notifications older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = abs($output->getError());
$exit_status = 11;
}
// Set the exit status if there were any errors.

View file

@ -15,6 +15,7 @@
<condition operation="notin" column="files.module_srl" var="exclude_module_srl" pipe="and" />
<condition operation="equal" column="files.isvalid" var="isvalid" pipe="and" />
<condition operation="equal" column="files.direct_download" var="direct_download" pipe="and" />
<condition operation="below" column="files.regdate" var="regdate_before" pipe="and" />
<group pipe="and">
<condition operation="like" column="files.source_filename" var="s_filename" pipe="or" />
<condition operation="more" column="files.file_size" var="s_filesize_more" pipe="or" />