LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-01-2009, 06:14 AM   #1
Radek84
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Rep: Reputation: 0
Question db backup script in gentoo


I ran db backup script in gentoo from command line (works ok).

This is my script (/scripts/dbbackup):
Quote:
#!/bin/bash
echo "Creating backup of database"
thedate=`date '+%Y%m%d'`
backupname="nameDBBackup"
filename="$backupname$thedate.sql"
echo $filename
mysqldump name > /backups/$filename
gzip /backups/$filename
scp /backups/$filename.gz hostname@ip address:serverbackups/$filename.gz
I want to run script automatically every week and when booting. (crontab and init.d)

This is my crontab script:
Quote:
* * * * 1 bash /scripts/dbbackup
But doesn't work I was wondering if anybody could help me??

Last edited by Radek84; 07-02-2009 at 04:17 AM.
 
Old 07-01-2009, 07:06 AM   #2
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
Quote:
Originally Posted by Radek84 View Post
This is my script (/scripts/database.sh):
First, put it in a code block so it is easier to read here:

Code:
#!/bin/bash
echo "Creating backup of database"
thedate=`date '+%Y%m%d'`
backupname="nameDBBackup"
filename="$backupname$thedate.sql"
echo $filename
mysqldump name > /backups/$filename
gzip /backups/$filename
scp /backups/$filename.gz hostname@ip address:serverbackups/$filename.gz
Then,

Quote:
Originally Posted by Radek84 View Post
I want to run script automatically every week and when booting. (crontab and init.d)

This is my crontab script:

* * * * 1 /scripts/database.sh

But it doesn't work I was wondering if anybody could help me??
"it doesn't work" doesn't work.

Please tell us how it doesn't work. What do you do to check it? What does it do? What error messages do you get?
 
Old 07-01-2009, 07:18 AM   #3
Radek84
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Unhappy

Hi mate,

When I want to run crontab dbbackup from command line I keep getting an error:
Quote:
"dbbackup":2: bad minute
errors in crontab file, can't install.
Please help me out...

Crontab script:

Quote:
# for vixie cron
#
# $Header: /var/cvsroot/gentoo-x86/sys-process/vixie-cron/files/crontab-3.0.1-r4,v 1.1 2005/03/04 23:59:48 ciaranm Exp $
#
#
# Global variables
SHELL=/bin/bash
PATH=/sbin:/bin:/scrpits
MAILTO=root
HOME=/
# check scripts in cron.hourly, cron.daily, cron.weekly and cron.monthly
0 * * * * root rm -f /var/spool/cron/lastrun/cron.hourly
1 3 * * * root rm -f /var/spool/cron/lastrun/cron.daily
15 4 * * 6 root rm -f /var/spool/cron/lastrun/cron.weekly
30 5 1 * * root rm -f /var/spool/cron/lastrun/cron.monthly
*/10 * * * * root test -x /usr/sbin/run-crons && /usr/sbin/run-icrons
Messages:
Quote:
Jul 2 08:20:01 rezapdev cron[2803]: (root) CMD (bash dbbackup)
Jul 2 08:20:01 new cron[2802]: (root) UNSAFE (/var/mail/root)
Jul 2 08:20:01 new cron[2805]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-icrons)
Jul 2 08:20:01 new cron[2804]: (root) UNSAFE (/var/mail/root)
Jul 2 08:30:01 new cron[2821]: (root) CMD (bash dbbackup)
Jul 2 08:30:01 new cron[2823]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-icrons)
Jul 2 08:30:01 new cron[2820]: (root) UNSAFE (/var/mail/root)
Jul 2 08:30:01 new cron[2822]: (root) UNSAFE (/var/mail/root)

Last edited by Radek84; 07-02-2009 at 03:08 AM.
 
Old 07-02-2009, 04:19 AM   #4
Radek84
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Original Poster
Rep: Reputation: 0
I'll be thankful for any help.
 
Old 07-02-2009, 04:41 AM   #5
nowonmai
Member
 
Registered: Jun 2003
Posts: 481

Rep: Reputation: 48
I'm pretty sure you have to specify when in the day to run as well as what day... something like

Code:
# Run at midnight on Monday
0 0 * * 1     /scripts/database.sh
On an unrelated note, it looks like you have created a new directory off / called scripts. It's not really recommended. If you want to have scripts, leave them in the users home, or a scripts directory off their home... or, in the case of root, in /root/scripts
You could then ln -s from that file to /etc/init.d, and from there to /etc/rcX.d to execute the script on startup
 
Old 07-02-2009, 05:25 AM   #6
Radek84
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Hi,

I've copied a dbbackup.sh to the user home and change crontab to:
Quote:
# use /bin/bash to run commands, overriding the default set by cron
SHELL=/bin/bash
#
# run every five minutes, every day
5 0 * * * $HOME/dbbackup.sh >> $HOME/tmp/out 2>&1
I've created a symlink in etc/init.d for dbbackup.

Some problems:
1. I don't have /etc/rcX.d.
2. When I run crontab dbbackup from command line I'm still getting an error:
Quote:
"dbbackup":2: bad minute
errors in crontab file, can't install.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with script to organise files into folders as part of DVD backup script jasybee2000 Linux - Newbie 5 06-15-2009 07:29 PM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 10:13 AM
Need backup script. gtrawoger Linux - Software 2 07-17-2006 07:31 AM
What backup script do you use? buldir Linux - Software 1 04-12-2005 02:57 PM
help with backup script dennis_89 Linux - Networking 2 06-29-2004 09:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration