<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Renzo Castillo</title>
    <description>The latest articles on DEV Community by Renzo Castillo (@renzocastillo).</description>
    <link>https://dev.to/renzocastillo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F739198%2F873eb309-918b-4630-ad63-36f8f360840c.jpeg</url>
      <title>DEV Community: Renzo Castillo</title>
      <link>https://dev.to/renzocastillo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/renzocastillo"/>
    <language>en</language>
    <item>
      <title>Simple handy bash script to update your PHP versions in cli and fpm with valet Linux</title>
      <dc:creator>Renzo Castillo</dc:creator>
      <pubDate>Sat, 02 Dec 2023 23:09:28 +0000</pubDate>
      <link>https://dev.to/renzocastillo/simple-handy-bash-script-to-update-your-php-versions-in-cli-and-fpm-with-valet-linux-311p</link>
      <guid>https://dev.to/renzocastillo/simple-handy-bash-script-to-update-your-php-versions-in-cli-and-fpm-with-valet-linux-311p</guid>
      <description>&lt;p&gt;Please consider that this script assumes that you already have php and valet Linux installed.&lt;/p&gt;

&lt;p&gt;Just add this to your bash script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;load_php() {
    version=$1
    case $version in
        7.4)
            sudo update-alternatives --set php /usr/bin/php7.4
            valet use 7.4
            valet restart
            ;;
        8.1)
            sudo update-alternatives --set php /usr/bin/php8.1
            valet use 8.1
            valet restart
            ;;
        8.2)
            sudo update-alternatives --set php /usr/bin/php8.2
            valet use 8.2
            valet restart
            ;;
        *)
            echo "Invalid PHP version: $version"
            ;;
    esac
}

phpvm() {
    if [ "$1" == "use" ]; then
        shift
        load_php "$1"
    else
        echo "Usage: phpvm use &amp;lt;php_version&amp;gt;"
    fi
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can do something like &lt;code&gt;phpvm use 7.4&lt;/code&gt; and you will get your php version 7.4 set at your cli and at your php-fpm service. &lt;/p&gt;

&lt;p&gt;Credits to &lt;a href="https://medium.com/@kenmutesh901/run-multiple-php-versions-in-ubuntu-nginx-z-shell-zsh-and-valet-176399a60669"&gt;Kenmutesh's post&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>valet</category>
      <category>bash</category>
      <category>linux</category>
    </item>
    <item>
      <title>¿ Cómo crear una migración en Laravel para actualizar de forma masiva a todas las claves foráneas  ?</title>
      <dc:creator>Renzo Castillo</dc:creator>
      <pubDate>Wed, 12 Jan 2022 23:59:22 +0000</pubDate>
      <link>https://dev.to/renzocastillo/como-crear-una-migracion-en-laravel-para-actualizar-de-forma-masiva-a-todas-las-claves-foraneas--38ap</link>
      <guid>https://dev.to/renzocastillo/como-crear-una-migracion-en-laravel-para-actualizar-de-forma-masiva-a-todas-las-claves-foraneas--38ap</guid>
      <description>&lt;p&gt;En este post te enseñaré a sacarle provecho a Doctrine , que es una librería, que está incluida como dependencia en laravel y en otros frameworks, y que permite gestionar a tus achivos de migraciones de la base de datos. Hace poco tuve que hacer una actualización de una base datos con cierta cantidad de tablas y la verdad que con sólo verlo me cansé en pensar tener que hacer un montón de migraciones secuenciales que prácticamente seguían la misma lógica.&lt;/p&gt;

&lt;p&gt;Primero les voy a dejar el código comentado y si quieren colocar esta migración les dejaré la versión sin comentar más abajo.&lt;/p&gt;

&lt;p&gt;Bueno el primer paso es obviamente crear tu migración con el comando&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan make:migration rebuild_foreign_keys_with_on_delete_cascade_on_update_cascade&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Una vez creado nuestro archivo de migración entramos a éste y creamos las funciones que pasaré a explicar dentro del código:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

class RebuildForeignKeysWithOnDeleteCascadeOnUpdateCascade extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // Nos conectamos a la BD y llamamos a DoctrineSchemaManager para hacer la magia.
        $con= Schema::getConnection()-&amp;gt;getDoctrineSchemaManager();
        // Aquí recuperamos a todos los nombres de las tablas en tu bd.
        $tb_names=$con-&amp;gt;listTableNames();
        // Empezaremos a rastrear a todas las claves foráneas por cada tabla
        foreach($tb_names as $tb_name){
            /* Aquí el nombre de la tabla será usado en la función indica la documentación
            de laravel para poder modificar las columnas y demás aspectos de la tabla*/
            Schema::table($tb_name, function (Blueprint $table) use ($tb_name,$con) {
                // Aquí dentro llamaremos a todas las claves foráneas de esta tabla en concreto
                $foreignKeys=$con-&amp;gt;listTableForeignKeys($tb_name);
                // Primero obviamente chequeamos si está vacío para evaluar si corremos o no esto.
                if(count($foreignKeys)){
                    /* Una vez que nos aseguramos que hay claves foráneas procedemos con la actualización
                     de ON DELETE NO ACTION a ON DELETE CASCADE. Empezamos a ir clave por clave*/
                    foreach($foreignKeys as $foreignKey){
                        // Recuperamos la columna local o sea la columna que guarda el id de la relación foránea
                        $local_col=$foreignKey-&amp;gt;getLocalColumns()[0];
                        // Aquí recuperamos el nombre de nuestra tabla foránea 
                        $foreign_table=$foreignKey-&amp;gt;getForeignTableName();
                        // Aquí obtenemos la columna de nuestra tabla foránea
                        $foreign_col=$foreignKey-&amp;gt;getForeignColumns()[0];
                        // Aquí obtenemos el nombre actual que tiene la clave foránea
                        $fk_name=$foreignKey-&amp;gt;getName();
                        /* Ahora procedemos a romper esta relación foránea,que es lo normal que haríamos
                        si quremos actualizar a una relación foránea de ON DELETE NO ACTION a CASCADE*/
                        $table-&amp;gt;dropForeign($fk_name);
                        /* Una vez rota la relación la reconstruimos asumiendo el comportamiento es cascada
                       para los eventos ON DELETE y ON UPDATE de nuestra base de datos */
                        $table
                        -&amp;gt;foreign($local_col, $fk_name)
                        -&amp;gt;references($foreign_col)
                        -&amp;gt;on($foreign_table)
                        -&amp;gt;onUpdate('CASCADE')
                        -&amp;gt;onDelete('CASCADE');
                    }
                }
            });

        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */

    /* Para el rollback de esta migración hacemos lo mismo con la única diferencia que
    ahora vamos a devolver la relación a ON DELETE NO ACTION.*/
    public function down()
    {
        $con= Schema::getConnection()-&amp;gt;getDoctrineSchemaManager();
        $tb_names=$con-&amp;gt;listTableNames();
        foreach($tb_names as $tb_name){
            Schema::table($tb_name, function (Blueprint $table) use ($tb_name,$con) {
                $foreignKeys=$con-&amp;gt;listTableForeignKeys($tb_name);
                if(count($foreignKeys)){
                    foreach($foreignKeys as $foreignKey){
                        $local_col=$foreignKey-&amp;gt;getLocalColumns()[0];
                        $foreign_table=$foreignKey-&amp;gt;getForeignTableName();
                        $foreign_col=$foreignKey-&amp;gt;getForeignColumns()[0];
                        $fk_name=$foreignKey-&amp;gt;getName();
                        $table-&amp;gt;dropForeign($fk_name);
                        $table
                        -&amp;gt;foreign($local_col, $fk_name)
                        -&amp;gt;references($foreign_col)
                        -&amp;gt;on($foreign_table)
                        -&amp;gt;onUpdate('NO ACTION')
                        -&amp;gt;onDelete('NO ACTION');
                    }
                }
            });

        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Espero haberles ayudado y que ahora tengan más tiempo . Si tienen alguna sugerencia, preguntas o mejoras pueden escribirme y procuraré responderles pronto.&lt;/p&gt;

&lt;p&gt;Saludos!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Cómo crear respaldos programados en la nube de tu base de datos con webmin</title>
      <dc:creator>Renzo Castillo</dc:creator>
      <pubDate>Wed, 12 Jan 2022 23:52:21 +0000</pubDate>
      <link>https://dev.to/renzocastillo/como-crear-respaldos-programados-en-la-nube-de-tu-base-de-datos-con-webmin-8nn</link>
      <guid>https://dev.to/renzocastillo/como-crear-respaldos-programados-en-la-nube-de-tu-base-de-datos-con-webmin-8nn</guid>
      <description>&lt;p&gt;Hola! El procedimiento para crear un respaldo programado en la nube con webmin se divide en los siguientes pasos:&lt;/p&gt;

&lt;p&gt;Configuración e instalación de la herramienta por línea de comandos de mega (megatools)&lt;br&gt;
Configuración de webmin para que acepte fechas en el nombre del archivo&lt;br&gt;
Configuración de respaldos programados de la base de datos&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Configuración e instalación de la herramienta por línea de comandos de mega (megatools)&lt;br&gt;
Para instalar megatools, configurarlo con su cuenta de mega.co.nz, y saber usar ‘megaput’ y ‘megarm’  , les recomiendo seguir las instrucciones de este post. Asimismo, una vez que terminen de configurar, les recomiendo hacer un par de testeos con megaput y megarm de cualquier archivo que tengan en su servidor para probar si su configuración estuvo bien realizada.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuración de webmin para que acepte fechas en el nombre del archivo&lt;br&gt;
Necesitamos otra configuración para hacer que webmin acepte ejecutar este tipo de reemplazos, de lo contrario pensará que el nombre que se coloque en nuestro archivo será ‘estático’. Para este caso usaremos el siguiente formato de fecha unix:  %Y-%m-%d . Esto deberá responder al año, mes y día respectivamente. Primero nos dirigimos a Webmin -&amp;gt; Servidores -&amp;gt; Servidor de Base de Datos MySQL. Luego arriba la izquierda encontramos un botón de configuración del módulo y lo seleccionamos para ver opciones más avanzadas. Aquí buscamos la opción Do strftime substitution of backup destinations?  Yes, y guardamos.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;3.Configuración de respaldos programados de la base de datos&lt;br&gt;
Para este caso lo primero que haremos será dirigirnos al panel de gestión de nuestro servidor de base de datos, que para este caso será MySQL.&lt;br&gt;
Nos dirigimos entonces a Webmin-&amp;gt; Servidores -&amp;gt; Servidor de Base de Datos MySQL.&lt;/p&gt;

&lt;p&gt;Una vez aquí, seleccionamos la base de datos de nuestro interés  y le damos a Respaldar Base de Datos. Aquí configuraremos los siguientes parámetros.&lt;/p&gt;

&lt;p&gt;Backup destination&lt;br&gt;
Seleccionamos ‘path on server’ y aquí debemos asegurarnos de indicar una ruta con parámetros basados en formato de fecha. Por lo cual nuestra ruta absoluta a colocar sería:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/cualquier-directorio/%Y-%m-%d-mi-base-de-datos.sql.gz &lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Other backup options&lt;br&gt;
Aquí les recomiendo seleccionar la compresión por gzip. Además de ello aquí se ejecutaron los comandos para depurar y para subir a la nube de mega cada archivo de respaldo .&lt;br&gt;
Command to run before backup&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rm "/cualquier-directorio/"$(date -d "$date -3 days" +"%Y-%m-%d")-mi-base-de-datos.sql.gz &amp;amp;&amp;amp; megarm --config=/root/.secrets/mega.cnf "/Root/mi-carpeta-mega/"$(date -d "$date -14 days" +"%Y-%m-%d")-mi-base-de-datos.sql.gz&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Ahora desglosaremos este comando en 2 partes:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rm "/cualquier-directorio/"$(date -d "$date -3 days" +"%Y-%m-%d")-mi-base-de-datos.sql.gz&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Este comando básicamente remueve al backup del servidor que sea de hace 3 días atrás, esto con la finalidad de optimizar recursos y retener menos backups.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;megarm --config=/root/.secrets/mega.cnf "/Root/mi-carpeta-mega/"$(date -d "$date -14 days" +"%Y-%m-%d")-mi-base-de-datos.sql.gz&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Este otro comando remueve del directorio mega a todos aquellos backups que sean de hace 14 días atrás, esto porque generalmente querrás tener respaldos más antiguos en la nube.&lt;/p&gt;

&lt;p&gt;Command to run after backup&lt;br&gt;
&lt;code&gt;megaput --config=/root/.secrets/mega.cnf --path=/Root/Yaku.app/DEV/backups --disable-previews "/backups/"$(date +%Y-%m-%d)-mi-base-de-datos.sql.gz&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Este comando se ejecuta posterior a la creación del backup en el servidor en la carpeta indicada, y su propósito es enviar el backup generado a la nube de MEGA.&lt;/p&gt;

&lt;p&gt;Backup schedule&lt;br&gt;
Send backup status email to&lt;br&gt;
Aquí colocamos un correo electrónico al cual quisieramos que nos llegue la confirmación del backup&lt;br&gt;
Send email for&lt;br&gt;
Aquí marcaremos ‘Only on failure’ para que no nos lleguen todo el tiempo, sólo en caso falle el respaldo.&lt;br&gt;
Scheduled backup enabled?&lt;br&gt;
Yes, at times chosen below ..Simple schedule ..Daily(at midnight)&lt;br&gt;
Una vez marcada estas opciones le damos a ‘Save’ y guardamos nuestra configuración. Si todo ha marchado correctamente, los respaldos deberían empezar a generarse y podrán visualizarlos directamente en su cuenta de Mega así como en su servidor webmin.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to create a migration in Laravel to massively update all foreign keys in your database </title>
      <dc:creator>Renzo Castillo</dc:creator>
      <pubDate>Thu, 04 Nov 2021 15:43:02 +0000</pubDate>
      <link>https://dev.to/renzocastillo/how-to-create-a-migration-in-laravel-to-massively-update-all-foreign-keys-in-your-database-5db9</link>
      <guid>https://dev.to/renzocastillo/how-to-create-a-migration-in-laravel-to-massively-update-all-foreign-keys-in-your-database-5db9</guid>
      <description>&lt;p&gt;In this post I will show you how to take advantage of Doctrine, which is a library that is included in laravel as well as in other frameworks, and it allows you to manage your php  migration files. I recently had to update a database with a certain number of tables and the truth is that just by looking at it I got tired of thinking about having to do a lot of sequential migrations that practically followed the same logic.&lt;/p&gt;

&lt;p&gt;I am going to leave you the commented code in case you want to place this migration file in your own laravel project.&lt;/p&gt;

&lt;p&gt;Well the first step is obviously to create your migration using  this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:migration rebuild_foreign_keys_with_on_delete_cascade_on_update_cascade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once our migration file is created, we enter it and create the functions that I will explain within the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php


use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class RebuildForeignKeysWithOnDeleteCascadeOnUpdateCascade extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // We connect to the DB and we call DoctrineSchemaManager to perform the magic for us.
        $con = Schema::getConnection()-&amp;gt;getDoctrineSchemaManager();
        // Here we retrieve all the database table names
        $tb_names = $con-&amp;gt;listTableNames();
        // Now we start to retrieve all the foreign key for each table
        foreach ($tb_names as $tb_name){
            // Here the table name will be used in the function that laravel docs indicate to modify columns and other table attributes.
            Schema::table($tb_name, function (Blueprint $table) use ($tb_name, $con){
                // Here we retrieve all foreign keys from this specific table
                $foreignKeys = $con-&amp;gt;listTableForeignKeys($tb_name);
                // First of all we obviously check if its empty in order to evaluate if it should be executed or not.
                if (count($foreignKeys))
                {
                    /* Once inside, we make sure that there are not foreign keys and we proceed to the update from ON DELETE NO ACTION to ON DELETE CASCADE
We loop key by key */
                    foreach ($foreignKeys as $foreignKey)
                    {
                        // Here we retrieve the local column, that means the column that saved the id of the foreign key relationship.
                        $local_col = $foreignKey-&amp;gt;getLocalColumns()[0];
                        // Here we retrieve the name of our foreign table
                        $foreign_table = $foreignKey-&amp;gt;getForeignTableName();
                        // Here we retrieve our foreign key column
                        $foreign_col = $foreignKey-&amp;gt;getForeignColumns()[0];
                        // Here we retrieve the foreign key name
                        $fk_name = $foreignKey-&amp;gt;getName();
                        /* Now we proceed to break the foreign relationship, which is the proper way to rebuild a foreign key relationship.*/
                        $table-&amp;gt;dropForeign($fk_name);
                        /* Once the foreign key relationship has been broken , we rebuild it  taking into account that new events should be  ON DELETE and ON UPDATE CASCADE */
                        $table
                            -&amp;gt;foreign($local_col, $fk_name)
                            -&amp;gt;references($foreign_col)
                            -&amp;gt;on($foreign_table)
                            -&amp;gt;onUpdate('CASCADE')
                            -&amp;gt;onDelete('CASCADE');
                    }
                }
            });
        }
    }


    /**
     * Reverse the migrations.
     *
     * @return void
     */


    /* The rollback migration function should be almost the same with only one differente which is to switch back the foreign key relationship to ON DELETE NO ACTION AND ON UPDATE NO ACTION.*/
    public function down()
    {
        $con = Schema::getConnection()-&amp;gt;getDoctrineSchemaManager();
        $tb_names = $con-&amp;gt;listTableNames();
        foreach ($tb_names as $tb_name)
        {
            Schema::table($tb_name, function (Blueprint $table) use ($tb_name, $con)
            {
                $foreignKeys = $con-&amp;gt;listTableForeignKeys($tb_name);
                if (count($foreignKeys))
                {
                    foreach ($foreignKeys as $foreignKey)
                    {
                        $local_col = $foreignKey-&amp;gt;getLocalColumns()[0];
                        $foreign_table = $foreignKey-&amp;gt;getForeignTableName();
                        $foreign_col = $foreignKey-&amp;gt;getForeignColumns()[0];
                        $fk_name = $foreignKey-&amp;gt;getName();
                        $table-&amp;gt;dropForeign($fk_name);
                        $table
                            -&amp;gt;foreign($local_col, $fk_name)
                            -&amp;gt;references($foreign_col)
                            -&amp;gt;on($foreign_table)
                            -&amp;gt;onUpdate('NO ACTION')
                            -&amp;gt;onDelete('NO ACTION');
                    }
                }
            });
        }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope that this method has helped you. If you have any suggestions, questions or improvements you can write to me and I will try to answer them as soon as possible.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>webdev</category>
      <category>migrations</category>
      <category>doctrine</category>
    </item>
    <item>
      <title>How to create scheduled  cloud backups of your database using mega with webmin</title>
      <dc:creator>Renzo Castillo</dc:creator>
      <pubDate>Thu, 04 Nov 2021 15:32:16 +0000</pubDate>
      <link>https://dev.to/renzocastillo/how-to-create-scheduled-cloud-backups-of-your-database-using-mega-with-webmin-1oop</link>
      <guid>https://dev.to/renzocastillo/how-to-create-scheduled-cloud-backups-of-your-database-using-mega-with-webmin-1oop</guid>
      <description>&lt;p&gt;Hi! The procedure to create a scheduled backup in the cloud with webmin is divided into the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuration and installation of the mega command line tool (megatools):&lt;/strong&gt; To install megatools, configure it with your mega.co.nz account, and know how to use 'megaput' and 'megarm', I recommend you to follow the instructions in this &lt;a href="http://blog.jeshurun.ca/technology/backup-files-mega-nz-from-command-line-linux-server"&gt;post&lt;/a&gt;. Once you have finish the installation and configuration of mega tools, I recommend doing a couple of tests with megaput and megarm of any file they have on their server to test if their configuration was well done.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuring webmin to accept dates in the file name:&lt;/strong&gt; We need another configuration to make webmin agree to run this type of override, otherwise it will think that the name that is placed in our file will be 'static'. For this case we will use the following unix date format:% Y-% m-% d. This should respond to the year, month and day respectively. First we go to Webmin -&amp;gt; Servers -&amp;gt; MySQL Database Server. Then at the top left we find a module configuration button and select it to see more advanced options. Here we look for the option Dostrftimesubstitution of backup destinations? Yes, and we save.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuring scheduled database backups:&lt;/strong&gt; In this case, the first thing we will do is go to the management panel of our database server, which for this case will be MySQL. We then go to Webmin-&amp;gt; Servers -&amp;gt; MySQL Database Server. Once here, we select the database of our interest and we click Backup Database. Here we will configure the following parameters.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Backup destination:&lt;/strong&gt; We select 'path on server' and here we must make sure to indicate a route with parameters based on date format. Therefore our absolute path to place would be:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;/ any-directory/%Y-%m-%d-mi-data-base.sql.gz&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Other backup options:&lt;/strong&gt;  Here I recommend selecting compression by gzip. In addition to this, the commands to debug and upload each backup file to the mega cloud were executed here.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Command to run before backup:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm "/ any-directory /" $ (date -d "$ date -3 days" + "% Y-% m-% d") - my-database.sql.gz &amp;amp;&amp;amp; megarm --config = /root/.secrets/mega.cnf "/ Root / my-mega-folder /" $ (date -d "$ date -14 days" + "% Y-% m-% d") - my-base-of -data.sql.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will break this command down into 2 parts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm "/ any-directory /" $ (date -d "$ date -3 days" + "% Y-% m-% d") - my-database.sql.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command basically removes the backup from the server that is 3 days old, this in order to optimize resources and retain fewer backups.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;megarm --config = / root / .secrets / mega.cnf "/ Root / my-mega-folder /" $ (date -d "$ date -14 days" + "% Y-% m-% d") - my-database-sql.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This other command removes from the mega directory all those backups that are from 14 days ago, this because generally you will want to have older backups in the cloud.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Command to run after backup:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;megaput --config = / root / .secrets / mega.cnf --path = / Root / Yaku.app / DEV / backups --disable-previews "/ backups /" $ (date +% Y-% m-% d ) -my-database-sql.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command is executed after the backup is created on the server in the indicated folder, and its purpose is to send the generated backup to the MEGA cloud.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backup schedule:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Send backup status email to:&lt;/strong&gt; Here we place an email to which we would like the backup confirmation to reach us&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Send email for:&lt;/strong&gt; Here we will mark 'Only on failure' so that they do not reach us all the time, only in case the backup fails.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scheduled backup enabled?&lt;/strong&gt; Yes, at times chosen below ..Simple schedule ..Daily (at midnight)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once these options are selected, we click 'Save' and save our configuration. &lt;/p&gt;

&lt;p&gt;If everything has gone well, the backups should start to be generated and you can view them directly in your Mega account as well as on your webmin server.&lt;/p&gt;

</description>
      <category>webmin</category>
      <category>linux</category>
      <category>database</category>
      <category>mega</category>
    </item>
  </channel>
</rss>
