Jump to content

Irritated with cron jobs...


aeroswat

Recommended Posts

Have you tried running the script on your own (given that you have ssh access) to make sure that it runs and parses just fine. You could have an error in the script and that is why.  You can "redirect" the output from that into a log file to test this as well:

 

*/5 * * * * /usr/bin/php -q /home2/aircborg/crons/cron-backup.php > /tmp/cron_log.log

 

Which should redirect the output to that log file where you can view it to see if there was an error etc.

Have you tried running the script on your own (given that you have ssh access) to make sure that it runs and parses just fine. You could have an error in the script and that is why.  You can "redirect" the output from that into a log file to test this as well:

 

*/5 * * * * /usr/bin/php -q /home2/aircborg/crons/cron-backup.php > /tmp/cron_log.log

 

Which should redirect the output to that log file where you can view it to see if there was an error etc.

 

thx. I'll try it out but I have tested the file before and it was working. I'll try to log out.

Here i'll post the code of the file too. Maybe someone can see something that might be causing a problem

 

        require_once('src/config.php');
$filePath='../backups/';
$dir = opendir($filePath) or die(mysql_error());
$filelist = array();
$filelist[0] = 99999999999999;
while ($file = readdir($dir)) { 
	if(eregi("\AUTOMATIC",$file)) {
		if(mktime((substr($file,33,2)=='AM' ? substr($file,28,2) : (substr($file,28,2)+12)),substr($file,31,2),0,substr($file,17,2),substr($file,20,2),substr($file,23,4)) < $filelist[0]) {
			$filelist[0] = mktime((substr($file,33,2)=='AM' ? substr($file,28,2) : (substr($file,28,2)+12)),substr($file,31,2),0,substr($file,17,2),substr($file,20,2),substr($file,23,4)); 
			$filelist[1] = $file;
		}
	}
}

$delfile = $filePath . $filelist[1];
unlink($delfile);

$mysqldump_version="1.02";

$output_messages=array();

$mysql_host=DB_HOST;
$mysql_database=DBA_DATABASE;
$mysql_username=DBA_USER;
$mysql_password=DB_PASSWORD;

$filename = "../backups/AUTOMATIC_orders_" . date('m_d_Y_h-iA') . ".sql";

function _mysqldump($mysql_database)
{
global $filename;
$sql="show tables;";
$result= mysql_query($sql) or die(mysql_error());
if( $result)
{
	while( $row= mysql_fetch_row($result))
	{
		_mysqldump_table_structure($row[0]);

		_mysqldump_table_data($row[0]);
	}
}
else
{
	//echo "/* no tables in $mysql_database */\n";
	$content = "/* no tables in $mysql_database */\n";
	$handle = fopen($filename, 'a+');
	fwrite($handle, $content);
	fclose($handle);
}
mysql_free_result($result);
}

function _mysqldump_table_structure($table)
{
global $filename;
$handle = fopen($filename, 'a+');
$content = "/* Table structure for table `$table` */\n";
fwrite($handle, $content);
	$content = "DROP TABLE IF EXISTS `$table`;\n\n";
	fwrite($handle, $content);

	$sql="show create table `$table`; ";
	$result=mysql_query($sql);
	if( $result)
	{
		if($row= mysql_fetch_assoc($result))
		{
			$content = $row['Create Table'].";\n\n";
			fwrite($handle, $content);
		}
	}
	mysql_free_result($result);	
}

function _mysqldump_table_data($table)
{
global $filename;
$handle = fopen($filename, 'a+');
$sql="select * from `$table`;";
$result=mysql_query($sql);
if( $result)
{
	$num_rows= mysql_num_rows($result);
	$num_fields= mysql_num_fields($result);

	if( $num_rows > 0)
	{
		$content = "/* dumping data for table `$table` */\n";
		fwrite($handle, $content);

		$field_type=array();
		$i=0;
		while( $i < $num_fields)
		{
			$meta= mysql_fetch_field($result, $i);
			array_push($field_type, $meta->type);
			$i++;
		}

		//print_r( $field_type);
		//echo "insert into `$table` values\n";
		$index=0;
		while( $row= mysql_fetch_row($result))
		{
			if($index % 100 == 0) {$content = "insert into `$table` values\n"; fwrite($handle, $content);}
			$content = "(";
			for( $i=0; $i < $num_fields; $i++)
			{
				if( is_null( $row[$i]))
					$content .= "null";
				else
				{
					switch( $field_type[$i])
					{
						case 'int':
							$content .= $row[$i];
							break;
						case 'string':
						case 'blob' :
						default:
							$stre = str_replace(";",":",mysql_real_escape_string($row[$i]));
							//echo "'".mysql_real_escape_string($row[$i])."'";
							$content .= "'".$stre."'";

					}
				}
				if( $i < $num_fields-1)
					$content .= ",";
			}
			$content .= ")";
			fwrite($handle, $content);

			if( $index < $num_rows-1 && (($index+1) % 100 != 0))
				$content = ",";
			else
				$content = ";";
			$content .= "\n";
			fwrite($handle, $content);

			$index++;
		}
	}
}
mysql_free_result($result);
$content = "\n";
fwrite($handle, $content);
fclose($handle);
}

function _mysql_test($mysql_host,$mysql_database, $mysql_username, $mysql_password)
{
global $output_messages;
$link = mysql_connect($mysql_host, $mysql_username, $mysql_password);
if (!$link)
{
   array_push($output_messages, 'Could not connect: ' . mysql_error());
}
else
{
	array_push ($output_messages,"Connected with MySQL server:$mysql_username@$mysql_host successfully");

	$db_selected = mysql_select_db($mysql_database, $link);
	if (!$db_selected)
	{
		array_push ($output_messages,'Can\'t use $mysql_database : ' . mysql_error());
	}
	else
		array_push ($output_messages,"Connected with MySQL database:$mysql_database successfully");
}

}

	_mysql_test($mysql_host,$mysql_database, $mysql_username, $mysql_password);
	$content = "/*mysqldump.php version $mysqldump_version */\n";
	$handle = fopen($filename, 'x+');
	fwrite($handle, $content);
	fclose($handle);
	_mysqldump($mysql_database) or die(mysql_error());	

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.