我想从管理员端备份站点文件夹,而不是使用cron

时间:2010-07-20 06:02:49

标签: php

我想备份站点文件夹但不使用cron。 我使用了复制命令,但是花了太多时间,有没有其他方法或脚本可以复制网站文件夹?

3 个答案:

答案 0 :(得分:1)

我对cronjob有类似限制的问题。

我的解决方案是创建一个Shell脚本 cronback.sh

#!/bin/sh

#############################
#       USER SETTINGS       #
#############################


 # MySQL Database Server
  SQLHOST="__DBHOSTNAME__"
 # MySQL Username
  SQLUSER="__DBUSERNAME__"
 # MySQL Password
  SQLPASS="__PASSWORD__"

 # Backup Target Directory - Ensure it is outside of the HTTP Root Directory
  BACKUPDIR="__BACKUP_TO__"
 # HTTP Root Directory
  HTTPDOCDIR="__BACKUP_FROM__"

 # Retain Backups for X Days
  RETAINDAYS=28


#############################
#   Do Not Edit Below This  #
#############################

 # Execution Timestamp
  ETIME=$(date +"%Y%m%d_%H%M%S")

#############################

echo "Automated Server Backup Script"
echo "      ----==========----"
echo ""

echo "Web Root Backup"
echo "===="
 # Get a List of Site Folder
  cd $HTTPDOCDIR
  SITELIST=`find -type d -maxdepth 1 | sort`
 # Loop through Folders
  for SITEONE in $SITELIST; do
    FOLDER=${SITEONE//.\/}
   # Do Not try and Backup the Whole Directory in One Hit
    if [ $FOLDER != '.' ]; then
      echo "| - $FOLDER"
      FIXED=${FOLDER//./_}
      SOURCE=$FOLDER
      TARGET=$BACKUPDIR$FIXED"_"$ETIME".gz"
      `tar -czf $TARGET $SOURCE &`
      echo "|   \ - Compressed to "$FIXED"_"$ETIME".gz"
    fi
  done
 # End Loop
echo ""

echo "MySQL Database Backup"
echo "===="
 # Get a List of Databases
  dblist=`mysql --host="$SQLHOST" --user="$SQLUSER" --password="$SQLPASS" --execute="show databases;"`
 # Loop through List of Databases
  for dbitem in $dblist; do
   # Do Not try and Backup the Header of 'Database' - Der!
    if [ $dbitem != 'Database' ]; then
     # Perfom the Backup
      DBFILE=$dbitem"_"$ETIME".sql.gz"
      echo "| - $dbitem"
      `mysqldump --host="$SQLHOST" --user="$SQLUSER" --password="$SQLPASS" --add-drop-table $dbitem | gzip > "$BACKUPDIR$DBFILE" &`
      echo "|   \ - Saved to '$DBFILE'"
    fi
  done
 # End Loop
echo ""

echo "Removing Old Backups"
echo "===="
echo "(Removing Backups older than $RETAINDAYS days.)"
 # Get a List of Files to Delete
  TODELETE=`find $BACKUPDIR -name '*.gz' -type f -mtime +$RETAINDAYS`
 # Loop through Files
  for ONEFILE in $TODELETE; do
    echo "| - $ONEFILE"
    `rm -f $ONEFILE`
    echo "|   \ - deleted"
  done
 # End Loop
echo ""

echo ""
echo "Backup Script Complete."
echo ""

然后我有一个调用该脚本的PHP脚本

<?php

set_time_limit( 2400 );

ob_start();
passthru( '__cronback.sh__' );
$retVal = ob_get_contents();
ob_end_clean();

@mail( 'me@myemail.com' , 'Cron Backup' , $retVal );

然后我每周都会触发此功能(所以28天的时间给我4个快照)然后我收到一封电子邮件,告诉我备份的内容和删除的内容。

答案 1 :(得分:0)

你的意思是否有任何其他复制命令?否。

答案 2 :(得分:0)

我使用拉链。我只需将所有内容拉上,然后保存即可。

请检查:UPHP folder backup

但是,如果你所拥有的东西花费的时间太长,那么实际上没有比复制它更快的方法了。