Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
topmug
Hangin' Around



Joined: Aug 11, 2005
Posts: 26

PostPosted: Tue Aug 23, 2005 8:21 am Reply with quote

Just a general question really im wondering if anyone knows a cron job to bacl up my database so i dont have to keep doing it manually?

Thanks in advance

Tom
 
View user's profile Send private message
BobMarion
Former Admin in Good Standing



Joined: Oct 30, 2002
Posts: 1037
Location: RedNeck Land (known as Kentucky)

PostPosted: Tue Aug 23, 2005 11:16 pm Reply with quote

Code:
<?php 


set_time_limit( 1200 );
$host="localhost"; // database host address
$dbuser=""; // database user name
$dbpswd=""; // database password
$mysqldb=""; // name of database
$day = (date("y-m-d"));
$path1 = "/home/YOURUSER/dumps"; // path to your backups storage MUST be CHMOD 777
$filename1 = "YOURDB_".$day.".sql";
$filename2 = "YOURDB_".$day.".sql.gz";
$old_path1 = getcwd();
chdir($path1);
if( file_exists($filename1) ) { unlink($filename1); }
if( file_exists($filename2) ) { unlink($filename2); }
system( "/usr/bin/mysqldump --opt --no-create-db --user=$dbuser --password=$dbpswd --host=$host $mysqldb > $filename1");
system( "tar -czf $filename2 $filename1");
unlink($filename1);
chdir($old_path1);
echo"SQL Backup Completed";

?>

Save this script as something like backup_sql.php and upload it into a protected directory somewhere in your web accessable directory structure.

The cron call will be something like:
GET [ Only registered users can see links on this board! Get registered or login! ] > /dev/null

_________________
Bob Marion
Codito Ergo Sum
http://www.nukescripts.net 
View user's profile Send private message Send e-mail Visit poster's website
topmug







PostPosted: Tue Aug 23, 2005 11:56 pm Reply with quote

Thanks mate ill give it ago, may i ask what exactly does this back up as when i do a backup on the website it backs up 40 odd MB and when running this quickly it backs up 7mb???

Thanks
 
BobMarion







PostPosted: Wed Aug 24, 2005 12:17 am Reply with quote

That script backs up only your database.

This script:
Code:
<?php 


set_time_limit( 1200 );
$day = (date("y-m-d"));
$path1 = "/home/YOURUSER"; // path to your backups storage
$path2 = "public_html/"; // path to your web root
$filename1 = "YOURSITE_".$day.".tar.gz";
$old_path1 = getcwd();
chdir($path1);
if( file_exists("dumps/".$filename1) ) { unlink("dumps/".$filename1); }
system( "tar -czf dumps/$filename1 $path2");
chdir($old_path1);
echo"Site Backup Completed";

?>

backups up your site assuming your public directory is public_html. Some servers have it as public, some as www, and many others Smile
 
topmug







PostPosted: Wed Aug 24, 2005 1:44 am Reply with quote

No thats all i want is my DB backed up, sorry when i unzipped the tar file it was 38 mb big so that is about the same as my normal backup.

Thanks for your help mate now time to get that cron working lol!
 
topmug







PostPosted: Wed Aug 24, 2005 3:24 am Reply with quote

okay i run the cron job -

GET [ Only registered users can see links on this board! Get registered or login! ] > /dev/null

and i get the error


<HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</H1>
500 Internal Server Error
</BODY>
</HTML>
 
Xiode
Regular
Regular



Joined: Jun 15, 2005
Posts: 78
Location: AR

PostPosted: Wed Aug 24, 2005 11:22 am Reply with quote

what is the cron for the site backup. Would it be the same concept as the db backup?

_________________
**Mental Note** Signature Goes Here! 
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Xiode







PostPosted: Wed Aug 24, 2005 11:56 am Reply with quote

OK! I just set this up, and it was Really Easy to do.

- First off make a new folder in the root of your site...
- Next go into cpanel, or whatever control panel you have, and secure the directory.
*** In cPanel it would be "Password Protect Directories".
- Set this up with a UserName & Password.
- Create the file "backup_sql.php" with the code that Bob provided above.
- Edit the info to what it needs to be to fit your site.
- Drop backup_sql.php in the secured folder via [ Only registered users can see links on this board! Get registered or login! ]
- Go back into cPanel, and go to "Cron jobs".
- Choose "Standard".
- Now in here you will see a bunch of settings that will allow you to select how often
you want this cron job to backup your DB. I would do a daily backup or maybe a
weekly backup depending upon the size of your DB and the ammount of webspace
that you have. In order to do this see where it says "Day(s)"? Select how
frequent you want this to run 1 = every day, and 7 = every week.
- The username and password on the cron tab is the same username and password that
you used to setup the secure directory.

You will have to clean the folders up. Delete the old backups after you have
downloaded them to your PC. This way your site doesn't become loaded with
stuff that you don't need.

This is really nice for me. Cause I have started an archive of my site. With
daily backups of my DB and weekly backups of the files on my site.


Now that you know how to do the SQL backup do the same thing for the site backup.


Last edited by Xiode on Wed Aug 24, 2005 12:02 pm; edited 2 times in total 
Xiode







PostPosted: Wed Aug 24, 2005 11:57 am Reply with quote

Bob do you mind if i post this on my site as a full pledge tutorial?
 
BobMarion







PostPosted: Wed Aug 24, 2005 12:43 pm Reply with quote

You have my full and complete permission
 
Xiode







PostPosted: Wed Aug 24, 2005 12:46 pm Reply with quote

Thank you.
 
CurtisH
Life Cycles Becoming CPU Cycles



Joined: Mar 15, 2004
Posts: 638
Location: West Branch, MI

PostPosted: Wed Aug 24, 2005 12:48 pm Reply with quote

Thanks guys, this is some extremely useful information.

_________________
Those who dream by day are cognizant of many things which escape those who dream only by night. ~Poe 
View user's profile Send private message Visit poster's website Yahoo Messenger
BobMarion







PostPosted: Wed Aug 24, 2005 1:09 pm Reply with quote

Xiode wrote:
what is the cron for the site backup. Would it be the same concept as the db backup?


Yes, same concept.
 
Xiode







PostPosted: Wed Aug 24, 2005 3:25 pm Reply with quote

You can find the full tutorials for this at.
[ Only registered users can see links on this board! Get registered or login! ]
 
CurtisH







PostPosted: Wed Aug 24, 2005 3:31 pm Reply with quote

Good job. Smile Great tutorial!

Don't you just love Mighty_Y's tutorial module? It is so much better than the KB mod.
 
Xiode







PostPosted: Wed Aug 24, 2005 3:34 pm Reply with quote

Making the DB backup one now.
 
BobMarion







PostPosted: Wed Aug 24, 2005 9:46 pm Reply with quote

Quote:
Before I say anything. You must understand that this site, anyone associated with it, Nukescripts.net, or anyone associated with that site are responsible for any lost data, damages, or anything else. You take complete responsiblity when using this. Use at your own risk.

Not to be picky but I think you forgot the word NOT in are responsible from both tutorials. Other then that one word they look really good Smile
 
Xiode







PostPosted: Wed Aug 24, 2005 10:05 pm Reply with quote

LMAO.... WOW. I can't believe i missed that.I probably read over it 3 times.
 
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Thu Aug 25, 2005 3:35 am Reply with quote

ROTFL
 
View user's profile Send private message
topmug







PostPosted: Thu Aug 25, 2005 4:06 am Reply with quote

OOPS, lol

Good Tut though mate, nice!
 
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Thu Aug 25, 2005 6:36 am Reply with quote

For those who don't seem to be able to use "GET" is there an alternative on a Linux machine?

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
djmaze
Subject Matter Expert



Joined: May 15, 2004
Posts: 727
Location: http://tinyurl.com/5z8dmv

PostPosted: Thu Aug 25, 2005 10:01 pm Reply with quote

Save the following code in /home/YOURNAME/sqlbackup.sh
Code:
#! /bin/sh

FILE1=sqlbackup-`date +%Y%m%d%H%M`.sql
DIR=/home/YOURNAME/
mysqldump -f -hlocalhost -u<loginname> -p<password> <dbname> --add-drop-table | gzip -9c >${DIR}${FILE1}.gz


Then run thru SSH or Cron
Code:
sh /home/YOURNAME/sqlbackup.sh
 
View user's profile Send private message Visit poster's website
montego







PostPosted: Thu Aug 25, 2005 10:03 pm Reply with quote

djmaze,

You are a scholar and a gentleman! Thank you!

montego
 
djmaze







PostPosted: Mon Aug 29, 2005 5:55 am Reply with quote

your welcome
 
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Wed Aug 31, 2005 11:53 pm Reply with quote

If you have access to cron but not telnet or ssh and cron doesnt like the GET function you could also try
Code:
php --quiet /home/yourpath/public_html/yourdirectory/filenamephp
 
View user's profile Send private message Send e-mail
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©