| General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun! |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-30-2004, 04:13 PM
|
#1
|
|
Member
Registered: Dec 2002
Distribution: freeBSD 4.9/6.0
Posts: 194
Rep:
|
mysql automated backup
I am running freeBSD 4.9. Is there a cronjob or some kinda of script that will automaticly backup mysql in 1 week intervals or however long i set it?
|
|
|
|
09-30-2004, 05:06 PM
|
#2
|
|
Member
Registered: Aug 2004
Location: Scotland
Distribution: Debian, Suse, Knoppix, Dyna:bolic, Mandrake [couple of years ago], Slackware [1993 or so]
Posts: 150
Rep:
|
call me old fashioned but I just tar.gz /var/lib/mysql
add the databases as you like. i.e. /var/lib/mysql /mysql
/var/lib/mysql /foo
Maybe there are cooler methods, but it seems to work.
|
|
|
|
09-30-2004, 05:09 PM
|
#3
|
|
Member
Registered: Aug 2004
Location: Scotland
Distribution: Debian, Suse, Knoppix, Dyna:bolic, Mandrake [couple of years ago], Slackware [1993 or so]
Posts: 150
Rep:
|
well and then the whole cronjob thingy
#!/usr/bin/perl
# Backup stuff to a remote server
use Net::FTP;
# Create tmp tar file of the $ARGV[0] directory
my $dir = shift;
my $host = shift || yourhost';
my $user = shift || 'foo';
my $pass = shift || 'pass;
my $remote_dir = shift || 'backups';
die "No directory to backup! - $dir\n" unless ($dir && -d $dir);
# Times
# We need this so we can allow a weeks worth of backups
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
my $filename;
if($dir =~ m|([^/]+)$|) {
$filename = $1 . '.tar.gz';
} else {
$filename = ' backup. '.$wday.'.'. $hour . '.' . $min . '.' . $sec .'.tar.gz';
}
# To the tar
system("tar zcf /tmp/$filename $dir");
my $ftp = Net::FTP->new($host, Debug => 0);
$ftp->login($user, $pass);
$ftp->cwd($remote_dir);
$ftp->delete($filename);
$ftp->binary;
$ftp->put('/tmp/'.$filename);
$ftp->quit;
unlink('/tmp/'.$filename);
then a shell script like
#!/bin/bash
./backup.pl /var/lib/mysql
echo "done mysql"
sleep 60
sync
./backup nextone
etc.
crontab -e
* * 1 * * /home/foo/backup
or so
Simple small efficient. Probably there are cooler things about i.e. webmin backup module depends really on your mileage.
Last edited by DrNeil; 09-30-2004 at 05:14 PM.
|
|
|
|
09-30-2004, 05:27 PM
|
#4
|
|
Member
Registered: Aug 2004
Location: Scotland
Distribution: Debian, Suse, Knoppix, Dyna:bolic, Mandrake [couple of years ago], Slackware [1993 or so]
Posts: 150
Rep:
|
If your ftp server supports the right commands maybe use ftpsync.
|
|
|
|
09-30-2004, 05:32 PM
|
#5
|
|
Member
Registered: Dec 2002
Distribution: freeBSD 4.9/6.0
Posts: 194
Original Poster
Rep:
|
Quote:
Originally posted by DrNeil
If your ftp server supports the right commands maybe use ftpsync.
|
sftpd?
|
|
|
|
09-30-2004, 07:07 PM
|
#7
|
|
Member
Registered: Dec 2002
Distribution: freeBSD 4.9/6.0
Posts: 194
Original Poster
Rep:
|
Thanks but i have figured out what im going to do. I am going to make a cronjob such as this:
1. Check to see if MySQL is running, and if not, to start it.
2. Run the script that performs the backup job.
This is a sample crontab entry for FreeBSD (which is what your server is running) that checks to see if MySQL is running (if it's not, it starts it) and does the backup:
Code:
*/15 * * * * your_userid /path/to/mysql startup_options
* 23 * * * your_userid /path/to/backup/script
The first line checks every 15 minutes to see if MySQL is running, and starts it if it's not
The second line runs the backup script every night at 11:00 PM.
The syntax for cron is:
minute hour day month wday user command
Also, the line that identified this system as FreeBSD is this:
FreeBSD 4.4-RELEASE (SERVER) #0
You can check the FreeBSD handbook for more info on using cron:
http://www.freebsd.org/doc/en_US.IS...uning-cron.html
sh name the script.sh
If the script has exe perms do
Code:
./name the script.sh
Examples how to set cron:
http://www.webmasters-central.com/t/cron.shtml
Code:
sh #!/bin/sh date=`date '+%m-%d-%y'`mysqldump -u database_username -pdatabase_password database_name > ~/mysql_backup/database_name.$date.sh
Where would the best place to put the .sh file?
|
|
|
|
09-30-2004, 08:39 PM
|
#8
|
|
Guru
Registered: Jan 2001
Posts: 24,128
Rep: 
|
Why ftp? FTP sucks and should be avoided if possible.
I say go with the last script mentioned using mysqldump to backup the database and then use scp or rsync using ssh keys for no password prompts mess in a script if you want to dump it to another server, which is smart for backing up, then its in two locations.. 
|
|
|
|
09-30-2004, 11:18 PM
|
#9
|
|
Member
Registered: Aug 2004
Location: Scotland
Distribution: Debian, Suse, Knoppix, Dyna:bolic, Mandrake [couple of years ago], Slackware [1993 or so]
Posts: 150
Rep:
|
You use ftp when your ISP provides you with FTP backup space the size of your harddisk for free
nix sftp etc dimdadum paddabum.
But if you have a full linux system to backup .. then do the whole ssh shingy dingy 
|
|
|
|
10-01-2004, 06:49 AM
|
#10
|
|
Guru
Registered: Jan 2001
Posts: 24,128
Rep: 
|
Quote:
Originally posted by DrNeil
You use ftp when your ISP provides you with FTP backup space the size of your harddisk for free
|
They do that in Scotland? Never heard of any ISP giving users backups space here in the USA. The most ISP's give with standard accounts is 5 to 10MB of space for a homepage...
|
|
|
|
10-01-2004, 02:46 PM
|
#11
|
|
Member
Registered: Aug 2004
Location: Scotland
Distribution: Debian, Suse, Knoppix, Dyna:bolic, Mandrake [couple of years ago], Slackware [1993 or so]
Posts: 150
Rep:
|
Germany: 69 Euro all inclusive, really cheap. You can get Debian or Suse on it.
Free traffic of 300 Gig. 2 gig Pentium 80 Gig hard disk 1 gig memory (Probably now cheaper, but you gonna have to start sometimes). It comes with external reboot possibilities, remote tty login, remote repair system etc.
Before we were in the States dead dear.
The system is up now 7 months and runs fine.
Opps I think the term problem is in ISP; i ment hosting provider which is kinda an internet service provider. I worked in Germany at one who did hosting and connectivity, I always mix that up.
Sorry if that wasn't clear.
The FTP space is obviously some big backup solution, which has 100's on them so sftp aint an option until they install it. Traffic for backup is free.
Last edited by DrNeil; 10-01-2004 at 02:53 PM.
|
|
|
|
10-01-2004, 09:08 PM
|
#12
|
|
Guru
Registered: Jan 2001
Posts: 24,128
Rep: 
|
Ahh.. yeah ISP here provides Internet.. Hosting provides hosting. I actually had a host provider that actually provided ssh access which was nice but now I don't believe in spending money for hosting, not when I can do it myself on my own ISP's connection. 
|
|
|
|
10-02-2004, 08:19 AM
|
#13
|
|
Member
Registered: Aug 2004
Location: Scotland
Distribution: Debian, Suse, Knoppix, Dyna:bolic, Mandrake [couple of years ago], Slackware [1993 or so]
Posts: 150
Rep:
|
Quote:
Originally posted by trickykid
host provider that actually provided ssh access which was nice
|
We have some finance guys as customers, so it's better to outsource with all the crap they want.  Exchange Server 9 Euro's to rent. I'll not gonna buy a windoze machine and then they suddenly decide they want something else next month. Also an NTL business line at home is more expensive than a hosted server with all quirks. Then I would to have buy an extra mchine for all that and when things get bigger and better I would have to buy the next machine.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:49 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|