Skip to main content
Topic: Little help with script needed (Read 5806 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: Little help with script needed

Reply #15

What about changing to something like this:
Code: [Select]
> /backupfolderpath/$sql_file");

Re: Little help with script needed

Reply #16

Which line please? There are a few $sql_file in the script...

Sorry, I am an absolute noob with PHP. I thought the line to change must be:

Code: [Select]
$sql_file = "dump_" . $db_name . "_" . date('Ymd_Hi') . ".sql";

to something like:

Code: [Select]
$sql_file = "/www/htdocs/(my-FTP-login)/(path-on-FTP)/dump_" . $db_name . "_" . date('Ymd_Hi') . ".sql";

Re: Little help with script needed

Reply #17

At the end of this one:
Code: [Select]
exec("mysqldump -u $db_name -p'$db_passwd' --allow-keywords --add-drop-table --complete-insert --quote-names $db_name > $sql_file");

Re: Little help with script needed

Reply #18

Okay, but now it isn't a .gz file anymore, the backup (in the right folder, yippie!) is an SQL file.  :o

Re: Little help with script needed

Reply #19

Code: [Select]
<?php

######## Einstellungen DB-Backup #############################################

$db_name = "d01b41f9";
$db_passwd = "FUkRXMwV23R5qk5L";
$destination = '/absolute/path/to/a/safe/location/'; // Do not forget the leading /

$sql_file = "dump_" . $db_name . "_" . date('Ymd_Hi') . ".sql";

####################################################################
$output = $destination . $sql_file;
exec("mysqldump -u $db_name -p'$db_passwd' --allow-keywords --add-drop-table --complete-insert --quote-names $db_name > $output");
exec("gzip $sql_file");

$datei = $sql_file . ".gz";
$link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$link = str_replace(basename(__FILE__),$datei,$link);
echo "Downloadlink: <a href='" . $link . "'>" . $datei . "</a><br>";

######## Dateien löschen, die älter als 14 Tage sind #############################################

    /*
    * Created on 30.01.2010 by Nico Schubert
    */
    $dir = $destination;
    $folder = dir($dir);
    while ($dateiname = $folder->read()) {
        if (filetype($dir.$dateiname) != "dir") {
            if (strtotime("-2 weeks") >
                @filemtime($dir.$dateiname)) {
                if (@unlink($dir.$dateiname) != false)
                echo $dateiname.' wurde gelöscht<br>';
                else
                echo $dateiname.' konnte nicht
                    gelöscht werden<br>';
                }
        }
    }
    echo "Suchen nach zu löschenden Dateien... Fertig";
    $folder->close();
    exit;

?>
Bugs creator.
Features destroyer.
Template killer.

Re: Little help with script needed

Reply #20

Thank you, Emanuele. Your script worked, but....

The backup is again an uncompressed SQL file. Why that?  :o

Re: Little help with script needed

Reply #21

That's because it is a similar solution to mine but longer one with minor mistakes I think (this include my earlier suggestion as well). @emanuele changed the variable to $output but forget to change the same variable $sql_file to $output below it. This is because the file is in other path now and need the same to be defined for the one below. I think.

Re: Little help with script needed

Reply #22

I understand not a word. I think.  :D

Re: Little help with script needed

Reply #23

I mean what about changing the latter $sql_file to $output:
Code: [Select]
exec("gzip $sql_file");

$datei = $sql_file . ".gz";
Otherwise the code is looking for the sql file and gzipped sql file at the script location and not in the set location? I think.

Re: Little help with script needed

Reply #24

Now the backup file has the .gz ending, but it is not packed (203 MB file size, while packed backup files are 36 MB).  :o

I tried this line:

Code: [Select]
exec("gzip $destination . $sql_file");

...so the gzip procedure will find the file in the other location, but it didn't work. File size is still 203 MB.

Code is now:

Code: [Select]
$destination = '/www/htdocs/xxx/backup/'; // Do not forget the leading /

$sql_file = "dump_" . $db_name . "_" . date('Ymd_Hi') . ".sql";

####################################################################
$output = $destination . $sql_file . ".gz";
exec("mysqldump -u $db_name -p'$db_passwd' --allow-keywords --add-drop-table --complete-insert --quote-names $db_name > $output");
exec("gzip $destination . $sql_file");

Re: Little help with script needed

Reply #25

Because interpretation changes the meaning of things. :P

Code: [Select]
<?php

######## Einstellungen DB-Backup #############################################

$db_name = "d01b41f9";
$db_passwd = "FUkRXMwV23R5qk5L";
$destination = '/absolute/path/to/a/safe/location/'; // Do not forget the leading /

$sql_file = "dump_" . $db_name . "_" . date('Ymd_Hi') . ".sql";

####################################################################
$output = $destination . $sql_file;
exec("mysqldump -u $db_name -p'$db_passwd' --allow-keywords --add-drop-table --complete-insert --quote-names $db_name > $output");
exec("gzip $output");

echo "Backup created<br>";

######## Dateien löschen, die älter als 14 Tage sind #############################################

    /*
    * Created on 30.01.2010 by Nico Schubert
    */
    $dir = $destination;
    $folder = dir($dir);
    while ($dateiname = $folder->read()) {
        if (filetype($dir.$dateiname) != "dir") {
            if (strtotime("-2 weeks") >
                @filemtime($dir.$dateiname)) {
                if (@unlink($dir.$dateiname) != false)
                echo $dateiname.' wurde gelöscht<br>';
                else
                echo $dateiname.' konnte nicht
                    gelöscht werden<br>';
                }
        }
    }
    echo "Suchen nach zu löschenden Dateien... Fertig";
    $folder->close();
    exit;

?>
Bugs creator.
Features destroyer.
Template killer.

Re: Little help with script needed

Reply #26

Great! This code worked! And you know what? I know what the solution was! Seems logical now that I see it. I think!  :D

Thank you both, @emanuele and @ahrasis, for your help with this stupid thing!  O:-)

Re: Little help with script needed

Reply #27

yw! :)
Bugs creator.
Features destroyer.
Template killer.