Datenbanksicherung per cronjob

Backup, Restore und Transfer von Daten
Post Reply
snick0r
Posts: 8
Joined: 2004-06-17 19:03
 

Datenbanksicherung per cronjob

Post by snick0r »

Ich möchte nun endlich, was ich mir seit 3 Jahren vornehme :roll:, eine Datenbanksicherung per cronjob einrichten. Auf meinem Server läuft Plesk, über das ich die Cronjobs erstellen kann (siehe Bild 1):
http://www.wheatus.org/cronjob.jpg

Dort habe ich eingestellt, dass der cronjob täglich nachts um 02:00h durchgeführt werden soll.

In der backup.sh steht folgendes:
http://www.wheatus.org/cronjob-datei.jpg

Sollte doch funktionieren, oder? Leider nicht, hab ich was falsch gemacht?
flo
Posts: 2223
Joined: 2002-07-28 13:02
Location: Berlin
 

Re: Datenbanksicherung per cronjob

Post by flo »

Ist die Suche kaputt? :-)

Im Ernst - wenn Du schon Hilfe bei Scripten möchtest, poste sie bitte - keiner wird das abtippen und korrigieren.

flo.
snick0r
Posts: 8
Joined: 2004-06-17 19:03
 

Re: Datenbanksicherung per cronjob

Post by snick0r »

Sorry ;)

Code: Select all

#!/bin/sh
DIR=`/xxx/httpdocs/backup/`
DATUM=`date ‘+%d-%m-%Y’`
mysqldump -uxxx -pxxx -hlocalhost xxx > $DIR/backup.sql
gzip -9 –best $DIR/backup.sql
mv $DIR/backup.sql $DIR/backup-${DATUM}.sql.gz
find $DIR/backup.sql -name *.sql.gz -mtime +5 -exec rm {} ;
Könnte daran was falsch sein?
User avatar
Joe User
Project Manager
Project Manager
Posts: 11191
Joined: 2003-02-27 01:00
Location: Hamburg
Contact:
 

Re: Datenbanksicherung per cronjob

Post by Joe User »

Manpages lesen und Pfade/Optionen selbst anpassen:

Code: Select all

#!/bin/bash
DIR="/xxx/httpdocs/backup/"
DATUM=`/bin/date '+%d-%m-%Y'`
/usr/bin/mysqldump -uxxx -pxxx -hlocalhost xxx > $DIR/backup.sql
/bin/gzip $DIR/backup.sql
/bin/mv $DIR/backup.sql $DIR/backup-${DATUM}.sql.gz
/bin/find $DIR/ -name *.sql.gz -mtime +5 -exec /bin/rm {} ;
exit 0
PayPal.Me/JoeUserFreeBSD Remote Installation
Wings for LifeWings for Life World Run

„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
flo
Posts: 2223
Joined: 2002-07-28 13:02
Location: Berlin
 

Re: Datenbanksicherung per cronjob

Post by flo »

Code: Select all

#!/bin/bash
DIR="/xxx/httpdocs/backup/"
DATUM=`/bin/date '+%d-%m-%Y'`
cd $DIR || exit 1
/usr/bin/mysqldump -uxxx -pxxx -hlocalhost xxx | gzip > backup-${DATUM}.sql.gz
/bin/find . -name *.sql.gz -mtime +5 -exec /bin/rm {} ;
exit 0
wäre mein Ansatz.
snick0r
Posts: 8
Joined: 2004-06-17 19:03
 

Re: Datenbanksicherung per cronjob

Post by snick0r »

Code: Select all

[root@xxx]# ./backup.sh
-bash: ./backup.sh: Permission denied
Manuell klappt es nicht :(
flo
Posts: 2223
Joined: 2002-07-28 13:02
Location: Berlin
 

Re: Datenbanksicherung per cronjob

Post by flo »

chmod +x gemacht? Oder vielleihct doch lieber ein chmod 0700 auf die Datei? :twisted:
snick0r
Posts: 8
Joined: 2004-06-17 19:03
 

Re: Datenbanksicherung per cronjob

Post by snick0r »

Hab die Rechte nun angepasst, hatte ich ganz vergessen, mache es nun auch nicht mehr über root. Allerdings bekomme ich nun folgendes:

Code: Select all

[userxxx@kekzdose ~]$ ./backup.sh
: No such file or directory
User avatar
Joe User
Project Manager
Project Manager
Posts: 11191
Joined: 2003-02-27 01:00
Location: Hamburg
Contact:
 

Re: Datenbanksicherung per cronjob

Post by Joe User »

Pfade angepasst?
PayPal.Me/JoeUserFreeBSD Remote Installation
Wings for LifeWings for Life World Run

„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
flo
Posts: 2223
Joined: 2002-07-28 13:02
Location: Berlin
 

Re: Datenbanksicherung per cronjob

Post by flo »

Leere Zeile am Anfang? :-)
User avatar
Joe User
Project Manager
Project Manager
Posts: 11191
Joined: 2003-02-27 01:00
Location: Hamburg
Contact:
 

Re: Datenbanksicherung per cronjob

Post by Joe User »

Gentoo Linux:

Code: Select all

#!/bin/sh

/usr/bin/mysqldump --flush-logs --master-data --lock-all-tables --opt --delete-master-logs --all-databases -uDbUsEr -pDbPaSs > /backup/mysqldump_`date +%Y%m%d%H`.sql

/usr/bin/mysqlcheck --analyze --check --auto-repair --extend --optimize --all-databases -uDbUsEr -pDbPaSs

/usr/bin/find /backup/ -type f -name *.sql -mtime +7 -print0 | /usr/bin/xargs -0 /bin/rm -f

exit 0
PayPal.Me/JoeUserFreeBSD Remote Installation
Wings for LifeWings for Life World Run

„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
snick0r
Posts: 8
Joined: 2004-06-17 19:03
 

Re: Datenbanksicherung per cronjob

Post by snick0r »

Problem ist, dass ich die Pfade nicht weiß :(
User avatar
Joe User
Project Manager
Project Manager
Posts: 11191
Joined: 2003-02-27 01:00
Location: Hamburg
Contact:
 

Re: Datenbanksicherung per cronjob

Post by Joe User »

Code: Select all

man which
PayPal.Me/JoeUserFreeBSD Remote Installation
Wings for LifeWings for Life World Run

„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
Post Reply