|
Tech Notes -
Linux
|
|
Written by Rick
|
|
Wednesday, 23 December 2009 17:01 |
|
Here's a handy script to run rsync from the command-line that prompts for source and destination paths;
#! /usr/bin/php
<?php ## Control CLI parameters if (($argv[1]=="") OR ($argv[2]=="")) { echo "Options not specified.\r\n"; echo "Program Usage: "; echo $argv[0]." <i.e.: /source/path> <i.e.: /destination/path>\r\n\r\n"; exit; }else{ $srcpath=$argv[1]; $dstpath=$argv[2]; }
$starttime=date('G:i:s', strtotime('now'));
echo "Starting rsync...\r\n"; $retval=system("sudo rsync -avrl --delete ".$srcpath." ".$dstpath, $retval); if (!$retval==false) { echo "Backup from ".$srcpath." to ".$dstpath." is complete!\r\n\r\n"; }else{ echo "Backup from ".$srcpath." to ".$dstpath." FAILED!\r\n\r\n"; }
$endtime=date('G:i:s',strtotime('now'));
echo "\r\nStart time - ".$starttime."\r\n"; echo "End time - ".$endtime."\r\n\r\n"; echo "Script complete!\r\n";
?>
Note:
- The sudo command in the system call allows the script to be used to sync root user files. This can be removed if that behavior is not desired.
- The script also utilizes the --delete feature of rsync to remove files in the destination that do not exist in the source. Evaluate that behavior for your application as well.
|