This topic is locked
[SOLVED]

 Dumpfile Database after Logout ?

1/17/2021 1:32:19 PM
PHPRunner General questions
A
Andreas G. author

I'm still studying, but even with the help, I can't make it.
I would like to create a backup of the database after logging out.
I managed to delete entries older than 30 days:

$sql = DB::PrepareSQL("DELETE FROM Kontaktliste WHERE DATEDIFF(NOW(), Datum) > 30");

DB::Exec( $sql );


But how can I have a backup created after the lougout?
Data:

$ db_name = "kd73296_tvk";

$ sqlfile = "dump". $ dbname. "". date ('Ymd_Hi'). ".sql";
Unfortunately, it doesn't work that way.

I now sit here all Sunday and read through every manual, but I can't find anything about backing up the database.
Please help again
thanks

Andreas

German translated with Google

M
MikeT 1/17/2021

Check SELECT INTO OUTFILE in mysql documentation.

If it doesn't have to run exactly on logout you could also setup a cron job on the server that dumps the data in some interval.

(Or if your mysql user has the necessary privileges you could use the mysql event scheduler to run the query).

A
Andreas G. author 1/18/2021

So it works for me now

Rights on the NAS were not set

PHPRUNNER-Version 10.4

PHP 7.2

MariaDB 10.x

set once after login and once after logout.
$db_name = "database";

$db_passwd = "password";
$sqlfile = "login" . $dbname . "" . date('Ymd_Hi:s') . ".sql";

create dump###

exec("mysqldump -u $db_name -p'$db_passwd' --quick --allow-keywords --add-drop-table --complete-insert --quote-names $db_name >$sql_file");

exec("gzip $sql_file");
and
$db_name = "database";

$db_passwd = "password";
$sqlfile = "logout" . $dbname . "" . date('Ymd_Hi:s') . ".sql";

create dump###

exec("mysqldump -u $db_name -p'$db_passwd' --quick --allow-keywords --add-drop-table --complete-insert --quote-names $db_name >$sql_file");

exec("gzip $sql_file");
It's definitely not ideal, but it works.
It's enough for my purpose.