I want to take backup of site folder but not using cron. I have used copy command,but it is taking too much time,is there any other way or script i can copy site folder?
Did you mean is there any other command for copying than copy? No.
I had a problem with a similar limitation on a cronjob.
My solution was to create a Shell Script 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 ""
I then have a PHP script which calls that Script
<?php
set_time_limit( 2400 );
ob_start();
passthru( '__cronback.sh__' );
$retVal = ob_get_contents();
ob_end_clean();
@mail( 'me@myemail.com' , 'Cron Backup' , $retVal );
I then trigger this function every week (so the 28 day period gives me 4 snapshots) and I get an email telling me what was backed up and what was deleted.
I use zip-ing. I just zip everything up, and save it.
Check this: UPHP folder backup
But if what you have is taking too long, there really is no faster way than to copy it.