Ok, the following is supposed to backup a path on the server into a tar.gz file and transfer it via FTP to another server. It doesn't work. I will pay anyone $10 to fix via paypal. Fix it here in this post then PM me your paypal address and I will pay you.
Code:
<?
//MD5 hash of the password used to access this page from a web-browser
//If this is not entered then the only way this script will be called
// is by the CRON job or from the server's shell
$password = "bb9bb5ad9a31c570ee8fc7a9702930b9";
//Path to the files to backup
//This can either be relative (../public_html/) or
// absolute (/home/username/public_html/)
$path = "/home/ie/public_html/";
$ftp_host = "backup4.trouble-free.net"; //Remote FTP host
$ftp_port = 21; //Remote FTP port
$ftp_user = "gandalf"; //Remote FTP username
$ftp_pass = "pass_removed_for_security"; //Remote FTP password
$ftp_dir = "/itselixir.com/files/"; //Remote FTP directory (where to store the backup)
//Temporary file to write the gzipped data to before uploading it
// -- Directory it resides in MUST be writable by the script!!
//This will have ".tar" or ".tar.gz" appended to it during the course of this scipt
$tmp_file = "backup_temp";
// ----- No User Editable Code Below This Line ----- //
//Is this a CRON job or a browser request?
if (isset($_SERVER['REMOTE_ADDR'])) {
//Presumably REMOTE_ADDR isn't set for shell scripts...
//so this must be a browser request
if (!isset($_GET['pass']) || md5($_GET['pass']) != $password) {
die();
}
}
//Tar all the files
//tar -cf archive.tar ./public_html/quotes/
//gzip -9 archive.tar
//result = archive.tar.gz -> archive.tar is deleted
echo "Tarring and GZipping - Please Wait........<br/>\r\n" . shell_exec("tar -zcf {$tmp_file}.tar.gz {$path}");
$ftpcon = ftp_connect($ftp_host, $ftp_port);
ftp_login($ftpcon, $ftp_user, $ftp_pass);
//Filename = files_08-05-2005_18-39.gz
ftp_put($ftpcon, $ftp_dir . "files_" . date("d-m-Y_H-i") . "_backup.tar.gz", $tmp_file.".tar.gz", FTP_BINARY);
ftp_close($ftpcon);
//Delete our temporary file
unlink($tmp_file.".tar.gz");
?>
I wouldent use PHP for this rather a backup script host localy on that server.
something like this script:
Code:
#!/bin/sh
#
# Backupscript, copyright (c) 2001 Jochem Kossen
#
# search & replace in vim :1,$s/|/>/g
#
# Initialization
#
BACKUPDIR="/drive2/backup" //dir to store the backup
IGNORE_EXTENTIONS="mp3 ogg mp3.temp core" //files to not include in backup
#
# Run script
#
echo "backup started..."
if [ -e ${BACKUPDIR}/backup-old.tar.gz ]; then
mv ${BACKUPDIR}/backup-old.tar.gz ${BACKUPDIR}/backup-old-OLD.tar.gz.tmp
echo "backup-old.tar.gz existed. Moved it to backup-old-OLD.tar.gz.tmp"
fi
if [ -e ${BACKUPDIR}/backup ]; then
cd ${BACKUPDIR}
tar zcf backup-old.tar.gz backup
chmod 600 ${BACKUPDIR}/backup-old.tar.gz
echo "created .tar.gz file of yesterday's backup directory"
rm -fr ${BACKUPDIR}/backup
echo "removed yesterday's backup directory"
fi
mkdir ${BACKUPDIR}/backup
echo "created a new backup directory for today"
cp -RLp /to-backup ${BACKUPDIR}/backup
echo "copied the symbolic links from /to-backup/ to real files"
# /etc, /usr/local/etc en /usr/home backuppen
#
cp -RPp /etc ${BACKUPDIR}/backup
mkdir ${BACKUPDIR}/backup/usr
mkdir ${BACKUPDIR}/backup/usr/local
cp -RPp /usr/local/etc ${BACKUPDIR}/backup/usr/local/
cp -RPp /usr/home ${BACKUPDIR}/backup/usr
echo "created backups of /etc, /usr/local/etc and /usr/home"
for i in ${IGNORE_EXTENTIONS}
do
find ${BACKUPDIR} -name "*.${i}" -print -exec rm -f {} \;
done
echo "removed every ignore"
/usr/local/bin/mysqldump -A -u backup --password=b4ckup >${BACKUPDIR}/backup/mysqldump.sql
chmod 600 ${BACKUPDIR}/backup/mysqldump.sql
echo "created mysql backup"
if [ -e ${BACKUPDIR}/backup-old-OLD.tar.gz.tmp ]; then
rm -f ${BACKUPDIR}/backup-old-OLD.tar.gz.tmp
echo "removed temporay old backup file ${BACKUPDIR}/backup-old-OLD.tar.gz.tmp"
fi
ls -al "${BACKUPDIR}/backup-old.tar.gz"
cd ${BACKUPDIR}/backup
echo "`pwd`:"
du -hd0
echo "done"