Linux command:rsync,和自己php程序实例备份

jackxiang 2008-6-25 18:58 | |
/usr/bin/rsync -vzrtup ./video_user_20080625_004312.txt 10.69.2.48::usersource_video/

aoyuntongji.php

<?php
require_once ("/data0/vshare/app/rank/config.php");
define("USER_SEARCH_IASK_LOG_PATH", "/data0/vshare/logs/user_search/iasks/");//删除的用户及视频日志目录(爱问)
echo "程序于 " . date("Y-m-d H:i:s") . " 开始执行:\n";
$date_d=date("d")-1;
if($date_d<10)
{
  $date_d="0".$date_d;
}
$iask_filename = USER_SEARCH_IASK_LOG_PATH.date("Ym")."/".$date_d."/boke_ay_" . date("Ymd", strtotime("-1 day")) .".log";
$iask_filename_html = USER_SEARCH_IASK_LOG_PATH.date("Ym")."/".$date_d."/boke_ay_" . date("Ymd", strtotime("-1 day")) .".html";
$conn_db_3306_r = @mysql_connect(DBHOST_VIDEO_R_aoyun, DBUSER_VIDEO_R_aoyun, DBPASSWD_VIDEO_R_aoyun) or
    die(DBHOST_VIDEO_R_aoyun.DBUSER_VIDEO_R_aoyun.DBPASSWD_VIDEO_R_aoyun."Can't connect to 3306 port readonly database");//长连接
//统计昨天登录过的用户个人中心信息
echo "正在从MySQL数据库中取出所有的用户userid,请稍候....";
//exit(0);
//$select_dt_user_r = @mysql_select_db("dt_video", $conn_db_3306_r) or die("Can't select database");
$select_dt_user_r = @mysql_select_db("dt_manage", $conn_db_3306_r) or die("Can't select database");
//$sql_tb_usertotal_r = "SELECT videoid,up_userid FROM tb_video_total where activeid = 0 limit 10";/*上线后打开*/
$starttime = date("Y-m-d 00:00:00", strtotime("-3 day"));
$endtime = date("Y-m-d 00:00:00");
$sql_tb_usertotal_r = "select videoid,up_userid from tb_video_activity where (adddate>'".$starttime."' or appr_time>'".$starttime."') and adddate<'".$endtime."' and appr_status=1 and active_status in(1,0) and conv_status=1 and del_status=0 and activeid=128;";/*上线后打开*/
$query_tb_usertotal_r = mysql_query($sql_tb_usertotal_r, $conn_db_3306_r) or die("Query Error:" .
    mysql_error() . "\n");
echo  $sql_tb_usertotal_r."\n";
echo "\n[取出所有的用户userid:完成]\n";
$i=0;
echo $iask_filename."\n";

if(file_exists($iask_filename))
{
    unlink($iask_filename);
}

while ($row_tb_usertotal_r = mysql_fetch_assoc($query_tb_usertotal_r))
{
     if (!($i % 2000))
    {
      sleep(1);        
    }
  $vid = $row_tb_usertotal_r['videoid'];
  $uid = $row_tb_usertotal_r['up_userid'];
  $result['vid'] = $vid;
  $result['uid'] = $uid;
  /*  
  echo "VID:". $result['vid'] = $vid."\n";
  echo "UID:".$result['uid'] = $uid."\n";
  */
  $content = getContent($result,$i);
  us_writeFile($content, $iask_filename, USER_SEARCH_IASK_LOG_PATH .date("Ym")."/".$date_d);
  $i=$i+1;
  
    
}
if (file_exists($iask_filename) && is_readable($iask_filename))
{
  echo "正在向爱问推送数据,请稍候....\n";
  //pclose(popen("touch {$iask_filename} && chmod 0664 {$iask_filename} && /usr/bin/rsync -vzrtup {$iask_filename} 10.69.2.48::usersource_video/",
        //"r"));
  $command="/usr/bin/rsync -avgt --progress --password-file=/usr/local/etc/rsyncd.secrets " . USER_SEARCH_IASK_LOG_PATH ."*"." backupuser@219.142.118.48::boke_2008_sum_olympic_video";
  echo $command."\n";
  pclose(popen("touch {$iask_filename} && chmod 0664 {$iask_filename} && $command",
        "r"));
  
  $command="/usr/bin/rsync -avgt --progress --password-file=/usr/local/etc/rsyncd.secrets " . USER_SEARCH_IASK_LOG_PATH ."*"." backupuser@172.16.153.70::olympic_video/";
  pclose(popen("touch {$iask_filename} && chmod 0664 {$iask_filename} && $command",
        "r"));
    $command="/usr/bin/rsync -avu " . $iask_filename ." 172.16.6.198::vblog/";
    pclose(popen("touch {$iask_filename} && chmod 0664 {$iask_filename} && $command",
        "r"));
    $command="cp {$iask_filename} {$iask_filename_html}";
    pclose(popen($command, "r"));
    $command="/usr/bin/rsync -avu {$iask_filename_html} {$iask_filename} 10.68.1.30::v_blog_sina_com_cn/htdocs/ay_data/";
    pclose(popen($command, "r"));
    $command="/usr/bin/rsync -avu {$iask_filename_html} {$iask_filename} 10.68.1.71::v_blog_sina_com_cn/htdocs/ay_data/";
    pclose(popen($command, "r"));
  
  echo "[推送完成]\n";
}



echo "\n[完成]\n";


echo "程序于 " . date("Y-m-d H:i:s") . " 执行结束。\n\n";

function us_path_validate($path)
{
    $arraypath = split("\/+", $path);
    $tmppath = "";
    for ($i = 0; $i < count($arraypath); $i++)
    {
        if ("" == $arraypath[$i])
            continue;
        $tmppath .= (0 == $i ? "":"/") . $arraypath[$i];
        if (!is_dir($tmppath))
        {
            if (!mkdir($tmppath, 0777))
            {
                return false;
            }
        }
    }
    return true;
}

function us_writeFile($content, $filename, $dirpath)
{
    if (!us_path_validate($dirpath))
        exit();
    $fp = fopen($filename, "a+");
    if (!@fwrite($fp, $content . "\n"))
    {
        @fclose($fp);
        return false;
    }
    fclose($fp);
    return true;
}

function getContent($result,$i)
{
  /*
         if($i==0)
  {
    $str  = "VID\tUID\t日期\n";
          $str .= $result['vid'] . "\t";//视频总量
          $str .= $result['uid'] . "\t";//userid,用户UID
          $str .= date("Y-m-d",strtotime("-1 day")). "";
    return $str;
  }else{
  */
    $str  = $result['vid'] . "\t";//视频总量
          $str .= $result['uid'] . "\t";//userid,用户UID
          $str .= date("Y-m-d",strtotime("-1 day"))   . "";
    return $str;
   //    }
}
?>

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/1083/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2008-10-7 17:08
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]