Current location: Hot Scripts Forums » Programming Languages » PHP » Help with Files Backup Script


Help with Files Backup Script

Reply
  #1 (permalink)  
Old 07-11-05, 06:37 AM
craigbrass craigbrass is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Help with Files Backup Script

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");

?>
Best Regards,
Craig Brass
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-11-05, 06:50 AM
Lafa's Avatar
Lafa Lafa is offline
Newbie Coder
 
Join Date: Jul 2005
Location: Moss, Norway
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
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"
Script (c) to Jochem Kossen 2001

just add it to a cron job like this:

cp backupscriptname.sh /etc/cron.daily/backupscript.sh
chmod 777 /etc/cron.daily/backupscipt.sh

if you want it to run every hour just swith /etc/cron.daily with /etc/cron.hourly or /etc/cron.weekly for weekly backup etc

this is offcourse if you got root access to server, and its a linux server.
__________________
TUXRocks, you dont.

Push it to the limit

Last edited by Lafa; 07-11-05 at 07:17 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-11-05, 07:47 AM
Xantus Xantus is offline
New Member
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I have a working version of your script if you still want it,
PM me if you do
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-11-05, 08:09 AM
craigbrass craigbrass is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Have PMed you but no reply. Please email it to craig -->at<-- craigbrass.net and then PM me your paypal address.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-11-05, 06:44 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
I would definitely recommend 'class-1 Backup/Restore' http://www.class1web.co.uk/downloads.php
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-12-05, 05:06 AM
Xantus Xantus is offline
New Member
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I hvae provided you the working code but you haven't paid yet
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 07-12-05, 10:00 AM
craigbrass craigbrass is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
I just had chance to try your modified version Xantus and it doesn't work. I get :-

"Tarring and GZipping - Please Wait........

Warning: unlink(backup_temp.tar): No such file or directory in /home/ie/public_html/backup/files_backup.php on line 53
Successfully backed-up"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 07-12-05, 10:17 AM
Xantus Xantus is offline
New Member
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
What do you enter as path?

EDIT: I sent you a PM with detials. I'm sorry for my previous post, I didn't know you hadden tested it yet

Last edited by Xantus; 07-12-05 at 10:26 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 11:17 AM
Automated script to delete certain files shib_s Script Requests 3 08-03-06 06:28 PM
Download files from another server using script! benweston Script Requests 5 01-17-06 10:29 AM
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 01:12 AM
Looking for Registered Members area access to files .. script zamen Script Requests 3 09-02-03 06:44 AM


All times are GMT -5. The time now is 12:52 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.