PHP Web Host - Quality Web Hosting For All PHP Applications Just Great Software
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
topmug
Hangin' Around


Joined: Aug 11, 2005
Posts: 26

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

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: 1043
Location: RedNeck Land (known as Kentucky)

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

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 to the forums!
> /dev/null
View user's profile Send private message Send e-mail Visit poster's website
topmug
Hangin' Around


Joined: Aug 11, 2005
Posts: 26

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

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
View user's profile Send private message
BobMarion
Former Admin in Good Standing


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

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

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
View user's profile Send private message Send e-mail Visit poster's website
topmug
Hangin' Around


Joined: Aug 11, 2005
Posts: 26

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

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!
View user's profile Send private message
topmug
Hangin' Around


Joined: Aug 11, 2005
Posts: 26

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

okay i run the cron job -

GET
Only registered users can see links on this board!
Get registered or login to the forums!
> /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>
View user's profile Send private message
Xiode
Regular
Regular


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

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

what is the cron for the site backup. Would it be the same concept as the db backup?
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Xiode
Regular
Regular


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

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

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 to the forums!

- 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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Xiode
Regular
Regular


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

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

Bob do you mind if i post this on my site as a full pledge tutorial?
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
BobMarion
Former Admin in Good Standing


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

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

You have my full and complete permission
View user's profile Send private message Send e-mail Visit poster's website
Xiode
Regular
Regular


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

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

Thank you.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
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 Back to top

Thanks guys, this is some extremely useful information.
View user's profile Send private message Visit poster's website Yahoo Messenger
BobMarion
Former Admin in Good Standing


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

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

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


Yes, same concept.
View user's profile Send private message Send e-mail Visit poster's website
Xiode
Regular
Regular


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

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

You can find the full tutorials for this at.
Only registered users can see links on this board!
Get registered or login to the forums!
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
CurtisH
Life Cycles Becoming CPU Cycles


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

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

Good job. Smile Great tutorial!

Don't you just love Mighty_Y's tutorial module? It is so much better than the KB mod.
View user's profile Send private message Visit poster's website Yahoo Messenger
Xiode
Regular
Regular


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

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

Making the DB backup one now.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
BobMarion
Former Admin in Good Standing


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

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

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
View user's profile Send private message Send e-mail Visit poster's website
Xiode
Regular
Regular


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

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

LMAO.... WOW. I can't believe i missed that.I probably read over it 3 times.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

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

ROTFL
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
topmug
Hangin' Around


Joined: Aug 11, 2005
Posts: 26

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

OOPS, lol

Good Tut though mate, nice!
View user's profile Send private message
montego
Site Admin


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

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

For those who don't seem to be able to use "GET" is there an alternative on a Linux machine?
View user's profile Send private message Visit poster's website
djmaze
Subject Matter Expert


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

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

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
Site Admin


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

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

djmaze,

You are a scholar and a gentleman! Thank you!

montego
View user's profile Send private message Visit poster's website
djmaze
Subject Matter Expert


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

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

your welcome
View user's profile Send private message Visit poster's website
Guardian2003
Site Admin


Joined: Aug 28, 2003
Posts: 6373
Location: Vsetin, Czech Republic

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

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 Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic

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
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum