LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   db backup script in gentoo (https://www.linuxquestions.org/questions/linux-server-73/db-backup-script-in-gentoo-736915/)

Radek84 07-01-2009 06:14 AM

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??

choogendyk 07-01-2009 07:06 AM

Quote:

Originally Posted by Radek84 (Post 3592788)
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 (Post 3592788)
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?

Radek84 07-01-2009 07:18 AM

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)

Radek84 07-02-2009 04:19 AM

I'll be thankful for any help.:confused:

nowonmai 07-02-2009 04:41 AM

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

Radek84 07-02-2009 05:25 AM

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.


All times are GMT -5. The time now is 03:59 AM.