Monday, February 23, 2009

embedded php in bat (batch) script. Winrar Backup Development files Example on Windows

Save following script as backupFiles.bat

@GOTO START
<?php
### embedded php in bat (batch) script.

// put some php code here
$now = date("ymd_his");

# where to store tar file.
$tarName = 'backup/' . $now . '_drupal.rar';

# specify a list of filename / folder name, separating by space.
$listFiles = 'drupal-6.9_Danny drupal-6.9_Karl';

exec( '"C:\\Program Files\\WinRAR\\WinRAR.exe"' . ' a ' . $tarName . ' -r ' . $listFiles );


/*
:START
@D:\UO\WebSites\PHP5.2.8\php.exe %0
@pause
@exit
*/
?>


PHP Version:
<?php
### embedded php in bat (batch) script.

// put some php code here
$now = date("ymd_his");

# where to store tar file.
$tarName = 'backup/' . $now . '_drupal.rar';

# specify a list of filename / folder name, separating by space.
$listFiles = 'drupal-6.10_dev drupal-6.9_Danny drupal-6.9_Karl';

hardFlush('Processing');

for($i=0; $i<3;$i++) {
echo ' . ';
ob_flush();
flush();
usleep(1000000);
}

echo 'Please Wait . . . Be patient ^_<

';
ob_flush();
flush();

exec( '"C:\\Program Files\\WinRAR\\WinRAR.exe"' . ' a ' . $tarName . ' -r ' . $listFiles );

echo 'Done :)
';


function hardFlush($msg = '') {
// Like said in PHP description above, some version of IE (7.0 for example)
// will not 'update' the page if less then 256 bytes are received
// Send 250 characters extra
echo str_pad(" ",250);
echo $msg;
ob_flush();
flush();
}
?>

No comments: