Page 1 of 2
MySQL Backup einer db an email senden
Posted: 2003-09-14 13:38
by eisdealer
Hi leute... Wie kann ich ein dump einer db erstellen und das an eine email senden lassen im abstand von 24 stunden?
Habe hier das halbe boartd durchschaut aber nicht das richtige gefunden...
MfG Eisi
Re: MySQL Backup einer db an email senden
Posted: 2003-09-14 15:47
by wirsing
RTFM man 5 crontab ; man 1 mysqldump
Re: MySQL Backup einer db an email senden
Posted: 2003-09-14 16:26
by nn4l
und um per shell script attachments per email zu verschicken:
http://home.clara.net/dwotton/unix/mail_files.htm
Re: MySQL Backup einer db an email senden
Posted: 2003-09-14 16:27
by wirsing
Das kann doch schon der cron machen - einfach ausgeben und die Ausgabe wird verschickt.
Re: MySQL Backup einer db an email senden
Posted: 2003-09-14 19:12
by nn4l
Falls Binärdaten gedumpt werden, dürfte das aber nicht mehr funktionieren.
Außerdem kann man beim Versenden als Attachment das File vorher komprimieren.
Re: MySQL Backup einer db an email senden
Posted: 2003-09-15 08:42
by eisdealer
um ehrlich zu sein habe ich von dem thead jetzt garnix kapiert was ich machen soll :oops:
Re: MySQL Backup einer db an email senden
Posted: 2003-09-15 10:34
by nn4l
Folgender Code funktioniert auf meinem Debian Server, sollte auch auf SuSE laufen.
In /etc/crontab folgende Zeile einbauen (wird täglich um 05:10 ausgeführt):
Code: Select all
10 05 * * * root /root/bin/backup-mysql
Und hier die Datei /root/bin/backup-mysql:
Code: Select all
#!/bin/bash
/opt/mysql/bin/mysqldump --all --complete-insert --add-drop-table --flush-logs --lock-tables --quick --user=root --password=geheim --host=127.0.0.1 datenbankname | gzip -best > /tmp/dbdump.sql.gz
cat <<EOF | /root/bin/mail_files backup@email.adresse -s "Das MySQL Backup" -f admin@email.adresse -b /tmp/dbdump.sql.gz
Hier ist das MySQL Backup.
Der Eisdealer
EOF
Pfadnamen natürlich ggf. anpassen.
Re: MySQL Backup einer db an email senden
Posted: 2003-09-15 11:02
by thorsten
nn4l, es wäre klasse, wenn du noch sagst, woher du mail_files hast.
Bei woody findet 'auto-apt search mail_files' kein Ergebnis.
Die Packetsuche auf debian.org zeigt mir auch in unstable keinen Treffer...
Re: MySQL Backup einer db an email senden
Posted: 2003-09-15 16:05
by wirsing
Thorsten wrote:nn4l, es wäre klasse, wenn du noch sagst, woher du mail_files hast.
Bei woody findet 'auto-apt search mail_files' kein Ergebnis.
Die Packetsuche auf debian.org zeigt mir auch in unstable keinen Treffer...
Re: MySQL Backup einer db an email senden
Posted: 2003-09-15 16:17
by thorsten
*batsch*
Danke wirsing :oops:
Re: MySQL Backup einer db an email senden
Posted: 2003-09-16 08:26
by eisdealer
nn4l wrote:Folgender Code funktioniert auf meinem Debian Server, sollte auch auf SuSE laufen.
In /etc/crontab folgende Zeile einbauen (wird täglich um 05:10 ausgeführt):
Code: Select all
10 05 * * * root /root/bin/backup-mysql
Und hier die Datei /root/bin/backup-mysql:
Code: Select all
#!/bin/bash
/opt/mysql/bin/mysqldump --all --complete-insert --add-drop-table --flush-logs --lock-tables --quick --user=root --password=geheim --host=127.0.0.1 datenbankname | gzip -best > /tmp/dbdump.sql.gz
cat <<EOF | /root/bin/mail_files backup@email.adresse -s "Das MySQL Backup" -f admin@email.adresse -b /tmp/dbdump.sql.gz
Hier ist das MySQL Backup.
Der Eisdealer
EOF
Pfadnamen natürlich ggf. anpassen.
Welche pfadnamen müsste ich da alles anpassen bzw wo müssen welche hin?
Wenn ich den mysqlpfad ändere kommt diese meldung:
Code: Select all
Server1:~/cronscripts/mysqlbackup # ./dump-xension
/usr/bin/mysqldump Ver 8.22 Distrib 3.23.55, for suse-linux (i686)
By Igor Romanenko, Monty, Jani & Sinisa
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Dumping definition and data mysql database or table
Usage: /usr/bin/mysqldump [OPTIONS] database [tables]
OR /usr/bin/mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR /usr/bin/mysqldump [OPTIONS] --all-databases [OPTIONS]
-A, --all-databases Dump all the databases. This will be same as
--databases with all databases selected.
-a, --all Include all MySQL specific create options.
-#, --debug=... Output debug log. Often this is 'd:t:o,filename`.
--character-sets-dir=...
Directory where character sets are
-?, --help Display this help message and exit.
-B, --databases To dump several databases. Note the difference in
usage; In this case no tables are given. All name
arguments are regarded as databasenames.
'USE db_name;' will be included in the output
-c, --complete-insert Use complete insert statements.
-C, --compress Use compression in server/client protocol.
--default-character-set=...
Set the default character set
-e, --extended-insert Allows utilization of the new, much faster
INSERT syntax.
--add-drop-table Add a 'drop table' before each create.
--add-locks Add locks around insert statements.
--allow-keywords Allow creation of column names that are keywords.
--delayed-insert Insert rows with INSERT DELAYED.
--master-data This will cause the master position and filename to
be appended to your output. This will automagically
enable --first-slave.
-F, --flush-logs Flush logs file in server before starting dump.
-f, --force Continue even if we get an sql-error.
-h, --host=... Connect to host.
-l, --lock-tables Lock all tables for read.
--no-autocommit Wrap tables with autocommit/commit statements.
-K, --disable-keys '/*!40000 ALTER TABLE tb_name DISABLE KEYS */;
and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */;
will be put in the output.
-n, --no-create-db 'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;'
will not be put in the output. The above line will
be added otherwise, if --databases or
--all-databases option was given.
-t, --no-create-info Don't write table creation info.
-d, --no-data No row information.
-O, --set-variable var=option
give a variable a value. --help lists variables
--opt Same as --add-drop-table --add-locks --all --quick
--extended-insert --lock-tables --disable-keys
-p, --password[=...] Password to use when connecting to server.
If password is not given it's solicited on the tty.
-P, --port=... Port number to use for connection.
-q, --quick Don't buffer query, dump directly to stdout.
-Q, --quote-names Quote table and column names with `
-r, --result-file=... Direct output to a given file. This option should be
used in MSDOS, because it prevents new line 'n'
from being converted to 'nr' (newline + carriage
return).
-S, --socket=... Socket file to use for connection.
--tables Overrides option --databases (-B).
-T, --tab=... Creates tab separated textfile for each table to
given path. (creates .sql and .txt files).
NOTE: This only works if mysqldump is run on
the same machine as the mysqld daemon.
-u, --user=# User for login if not current user.
-v, --verbose Print info about the various stages.
-V, --version Output version information and exit.
-w, --where= dump only selected records; QUOTES mandatory!
-X, --xml dump a database as well formed XML
-x, --first-slave Locks all tables across all databases.
EXAMPLES: "--where=user='jimf'" "-wuserid>1" "-wuserid<1"
Use -T (--tab=...) with --fields-...
--fields-terminated-by=...
Fields in the textfile are terminated by ...
--fields-enclosed-by=...
Fields in the importfile are enclosed by ...
--fields-optionally-enclosed-by=...
Fields in the i.file are opt. enclosed by ...
--fields-escaped-by=...
Fields in the i.file are escaped by ...
--lines-terminated-by=...
Lines in the i.file are terminated by ...
Default options are read from the following files in the given order:
/etc/my.cnf /var/lib/mysql/my.cnf ~/.my.cnf
The following groups are read: mysqldump client
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit
--no-defaults Don't read default options from any options file
--defaults-file=# Only read default options from the given file #
--defaults-extra-file=# Read this file after the global files are read
Possible variables for option --set-variable (-O) are:
max_allowed_packet current value: 16776192
net_buffer_length current value: 1047551
./dump-xension: line 4: --flush-logs: command not found
./dump-xension: line 5: --host=localhost: command not found
./dump-xension: line 7: /root/cronscripts/mysqlbackup/mail_files: No such file or directory
Server1:~/cronscripts/mysqlbackup #
jetzt fehlt nur noch das datum...
Posted: 2004-04-04 09:05
by Anonymous
Hi,
hab das Backup-Script zum Laufen gebracht. Jetzt hätt ich noch gern das Datum im Dateinamen. Ausgabe demnach: 2004-04-04.sql. (YYYY-MM-DD).
Danke für die Hilfe!
Peter
Re: MySQL Backup einer db an email senden
Posted: 2004-04-04 11:11
by Anonymous
hab's selbst rausgefunden:
Code: Select all
#!/bin/bash
DATUM=`date +"%y%m%d"`;
FILE="dump_${DATUM}.sql.gz"
/usr/bin/mysqldump --all --complete-insert --add-drop-table --flush-logs --lock-tables --quick --user=root --password=geheim --host=localhost nrwz | gzip -best > /tmp/${FILE}
cat <<EOF | /root/bin/mail_files me@xyz.de -s "MySQL Backup vom ${DATUM}" -f me@xyz.de -b /tmp/${FILE}
Hier ist das MySQL Backup vom ${DATUM}.
erzeugt eine JJMMDD.sql.gz
Peter
Re: MySQL Backup einer db an email senden
Posted: 2004-04-05 12:03
by [monk]
ähh warum so umständlich ?
das braucht man nicht in files umzulenken und was weiß ich alles.
das ist ein einfacher einzeiler in der crontab:
Code: Select all
0 0 * * * mysqldump -u <user> -p<pwd> -B datenbank1 datenbank2 | gzip -c9 |uuencode "backup.sql.gz"| mail -s 'DB backup from blub' empfaenger@mail.de
Gruß
Michael
Re: MySQL Backup einer db an email senden
Posted: 2004-04-05 13:46
by Anonymous
jupp, das ist eine smarte Geschichte, monk. Aber ich hab's jetzt ganz gern ein bisserl umständlicher. Hab meine Funktion um ein paar Features erweitert. Und auf meinen Fall passt sie gut, brauche die Files nämlich einerseits auf dem Server, andererseits per Mail an mich.
Merci
Peter
Re: MySQL Backup einer db an email senden
Posted: 2004-04-16 13:21
by tobias1985
[MONK] wrote:ähh warum so umständlich ?
das braucht man nicht in files umzulenken und was weiß ich alles.
das ist ein einfacher einzeiler in der crontab:
Code: Select all
0 0 * * * mysqldump -u <user> -p<pwd> -B datenbank1 datenbank2 | gzip -c9 |uuencode "backup.sql.gz"| mail -s 'DB backup from blub' empfaenger@mail.de
Gruß
Michael
Habs genauso kopiert, Daten wie Username, Passwort, Email-Adresse geändert. Die Mail wird verschickt, allerdings ohne Inhalt/Anhang. Namen der Datenbanken stimmen aber. Muss <> bleiben? Fehlt da ein Leerzeichen vor <pwd> ?
Danke schonmal.
Re: MySQL Backup einer db an email senden
Posted: 2004-04-16 13:23
by captaincrunch
Muss <> bleiben?
Nein.
Fehlt da ein Leerzeichen vor <pwd> ?
Nochmal nein.
Re: MySQL Backup einer db an email senden
Posted: 2004-04-16 13:29
by tobias1985
CaptainCrunch wrote:Muss <> bleiben?
Nein.
Fehlt da ein Leerzeichen vor <pwd> ?
Nochmal nein.
OK. Funktioniert trotzdem nicht. Die Mail ist immer leer. Hier nochmal mein Inhalt der Crontab:
27 13 * * * mysqldump -u Username -pPasswort -B dbname_1 dbname_2 dbname_3 dbname_4 | gzip -c9 |uuencode "backup.sql.gz"| mail -s 'DB backup from db'
email@adresse.de
Re: MySQL Backup einer db an email senden
Posted: 2004-04-16 13:38
by [monk]
was ergibt denn die ausgaben von
Code: Select all
mysqldump -u Username -pPasswort -B dbname_1 dbname_2 dbname_3 dbname_4
auf der console ?
ist uuencode installiert ?
ist gzip installiert ?
funktioniert der normale mailversand per mail auf der console ?
Gruß
Michael
Re: MySQL Backup einer db an email senden
Posted: 2004-04-16 13:46
by tobias1985
[MONK] wrote:was ergibt denn die ausgaben von
Code: Select all
mysqldump -u Username -pPasswort -B dbname_1 dbname_2 dbname_3 dbname_4
auf der console ?
ist uuencode installiert ?
ist gzip installiert ?
funktioniert der normale mailversand per mail auf der console ?
Gruß
Michael
Auf der Konsole werden scheinbar meine ganzen Datenbanken angezeigt. Fehler konnte ich keine sehen.
Gzip habe ich per Yast gesucht und es wurde als installiert gefunden. uuencode habe ich auch per Yast gesucht, wurde aber weder als installiert noch als zu installierendes Paket gefunden. Wo bekomm ich das her und wie installiere ich das?
Der normale Mailversand scheint ja zu gehen. Der Cron schickt ja die Mail, nur dass sie eben leer ist.
Re: MySQL Backup einer db an email senden
Posted: 2004-04-16 13:57
by captaincrunch
Re: MySQL Backup einer db an email senden
Posted: 2004-04-16 13:59
by tobias1985
Wenn ich das eingebe passiert garnichts.
Re: MySQL Backup einer db an email senden
Posted: 2004-04-16 14:04
by captaincrunch
Installier das zuständige RPM, dann klappts auch.
Re: MySQL Backup einer db an email senden
Posted: 2004-04-16 14:27
by tobias1985
CaptainCrunch wrote:Installier das zuständige RPM, dann klappts auch.
Hm. Ã?ber google hab ich nichts gefunden wo ich uuencode runterladen kann. Weiß einer zufällig die URL?
Das RPM installier ich doch einfach indem ich ./name.rpm eingeb oder?
Re: MySQL Backup einer db an email senden
Posted: 2004-04-16 15:20
by tobias1985
So. Ok. Installiert.
Die Mail wird verschickt und diesmal auch mit Inhalt. Allerdings nicht mit Anhang sondern in der Mail steht sowas:
<input type='hidden' name='copy_body' value='Am 16.04.2004 um 15:15 Uhr haben Sie geschrieben: > begin 644 backup.sql.gz > M'XL(`%7<?T`"`]1<S9+;1I(^KYX"OKBED<2N_QY%+-MN>CL:31JF7O>BX* > MD`V2</,O0%`MZ;GV??:RSS"G.6P6@`(*)-A=27G6,8Z63!'XD%F5F5]E5A;Z > MZ=/DU:>K_WB97.^6F2,&'OP]"G)']>;MGR6(]21=S^)C`?]^G93I.M]FS > M9+<MWM]F8_Z>PJTG_N>$7&7%AZQ(X,V7Z_^C88'TGV=+&>/6C4^&Y7%-FJ > M/";[P8/OWEY>O+M,OK]X=_'MQ=5E<OZ'KSCCE"4O_I2_NN[Y/*_7ER]N_K# > M>8#[YL&#G^#.WA>UM'?I>)$EV[+83<I=D273=9&4U7=GZ6I:I+-L=19*!9DO > M+Q-_*7GX($GRZZ3,/I:5[-<_O7SY!+ZK+A]^77UQ.TRS1>'W]ZD939;%_G` > M8SYG^=YC'CQ*WOWRYO+YJTOKBY>M:/['DR<KV;)-<SE:$]>/'ZZO+MN^3% > MZW=_[8;V\7+GRZODH=G].S)V7^"&G^?3E=9DD_F+AM<E6FQ3);_>./</4% > M?#=/QFF6,/CEUE[0^GN2#[O:NQJE-S"<V;9O'1W.&2Y'N?I]M_A?]EV/;K. > MX*O;?'6]OMW")TJT%9PIJX>?7./DNQW5E*3""7Y[ZTD9?<K*7YW);53O[X > MO%DO01Z(S08BM+MX-$:'@_&+8VM?K8B1;'>;S;HH!X;17/G_'D-/H0AB9B<2 > M,]LG9A9C^/&N+->K]T[I@2D+KOIIRU?E0_ZHG8PDW97K]_EJ4F3.4F[&N7L > M_;:8)!_28C)/BX=,RN#^ZVR:[A9E<G;F[DW?SXML&G7K)MUN;YW]_,WF^%/A > MKNH6>OR6U>=TOG@_R:["<
Und so weiter. Steht ziemlich viel von dem Schrott in der Mail.