<?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: minnogit</title>
    <description>The latest articles on DEV Community by minnogit (@minnogit).</description>
    <link>https://dev.to/minnogit</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%2F673072%2F4304ed14-f112-401b-bdfd-3d751d9879fb.png</url>
      <title>DEV Community: minnogit</title>
      <link>https://dev.to/minnogit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/minnogit"/>
    <language>en</language>
    <item>
      <title>Hardening Apache Reverse Proxy in produzione</title>
      <dc:creator>minnogit</dc:creator>
      <pubDate>Tue, 17 Feb 2026 11:52:41 +0000</pubDate>
      <link>https://dev.to/minnogit/hardening-apache-reverse-proxy-in-produzione-3ffc</link>
      <guid>https://dev.to/minnogit/hardening-apache-reverse-proxy-in-produzione-3ffc</guid>
      <description>&lt;h3&gt;
  
  
  Guida completa a timeout, worker e gestione dei carichi applicativi
&lt;/h3&gt;

&lt;p&gt;In un'infrastruttura dove &lt;strong&gt;Apache HTTP Server&lt;/strong&gt; funge sia da frontend (TLS, routing, bilanciamento) che da tramite verso container &lt;strong&gt;Docker&lt;/strong&gt;, la stabilità non dipende dalla potenza dell'hardware, ma dalla &lt;strong&gt;coerenza della catena dei timeout&lt;/strong&gt;, dai limiti del sistema operativo e dal dimensionamento dell'intero stack applicativo.&lt;/p&gt;

&lt;p&gt;Questa guida è focalizzata sul caso reale in cui:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Apache frontend agisce da reverse proxy e load balancer&lt;/li&gt;
&lt;li&gt;Il backend applicativo gira in container&lt;/li&gt;
&lt;li&gt;In alcuni casi Apache è anche il web server dentro il container&lt;/li&gt;
&lt;li&gt;L’applicazione è PHP (ma i principi restano validi anche per Python o altri stack)&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  1. Il Sistema Operativo: Preparare il terreno (Systemd)
&lt;/h1&gt;

&lt;p&gt;Prima di configurare Apache, dobbiamo assicurarci che il sistema operativo gli permetta di lavorare.&lt;/p&gt;

&lt;p&gt;Sui sistemi moderni come &lt;strong&gt;Debian&lt;/strong&gt; o &lt;strong&gt;Ubuntu&lt;/strong&gt;, il limite di processi e thread per servizio è gestito da &lt;strong&gt;systemd&lt;/strong&gt; tramite i Cgroups.&lt;/p&gt;

&lt;h2&gt;
  
  
  Il problema
&lt;/h2&gt;

&lt;p&gt;Sotto carico Apache può raggiungere il limite di task e generare errori nei log simili a:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Fork Rejected
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  La soluzione
&lt;/h2&gt;

&lt;p&gt;Aumentare &lt;code&gt;TasksMax&lt;/code&gt; per il servizio Apache.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl edit apache2.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inserire:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[Service]&lt;/span&gt;
&lt;span class="py"&gt;TasksMax&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;3000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Applicare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl daemon-reload
systemctl restart apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Per un server con &lt;strong&gt;4 GB RAM e ~400 worker&lt;/strong&gt;, 3000 è un valore equilibrato.&lt;/p&gt;




&lt;h1&gt;
  
  
  2. Monitoraggio in tempo reale: i comandi “Manometro”
&lt;/h1&gt;

&lt;p&gt;Per capire se il limite è corretto, interroga direttamente i Cgroups:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; /sys/fs/cgroup/system.slice/apache2.service/pids.current
&lt;span class="nb"&gt;cat&lt;/span&gt; /sys/fs/cgroup/system.slice/apache2.service/pids.max
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Se &lt;code&gt;pids.current&lt;/code&gt; si avvicina a &lt;code&gt;pids.max&lt;/code&gt;, il server inizierà a rifiutare connessioni.&lt;/p&gt;

&lt;p&gt;Questo è il primo indicatore reale di saturazione.&lt;/p&gt;




&lt;h1&gt;
  
  
  3. Il Motore: MPM Event dimensionato per 4GB RAM
&lt;/h1&gt;

&lt;p&gt;Il modulo &lt;strong&gt;MPM Event&lt;/strong&gt; gestisce le connessioni in modo asincrono, evitando che i thread restino bloccati su KeepAlive.&lt;/p&gt;

&lt;p&gt;Configurazione:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/etc/apache2/mods-available/mpm_event.conf&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apache"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nl"&gt;IfModule&lt;/span&gt;&lt;span class="sr"&gt; mpm_event_module&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="nc"&gt;ServerLimit&lt;/span&gt;              16
    &lt;span class="nc"&gt;StartServers&lt;/span&gt;             3
    &lt;span class="nc"&gt;ThreadsPerChild&lt;/span&gt;          25
    &lt;span class="nc"&gt;MaxRequestWorkers&lt;/span&gt;        400
    &lt;span class="nc"&gt;MinSpareThreads&lt;/span&gt;          25
    &lt;span class="nc"&gt;MaxSpareThreads&lt;/span&gt;          75
    &lt;span class="nc"&gt;MaxConnectionsPerChild&lt;/span&gt;   10000
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nl"&gt;IfModule&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Perché questi numeri?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;16 processi × 25 thread = 400 richieste simultanee&lt;/li&gt;
&lt;li&gt;circa 800 MB occupati da Apache&lt;/li&gt;
&lt;li&gt;RAM restante per PHP, sistema e cache&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Se PHP cresce, Apache deve ridursi.&lt;/p&gt;




&lt;h1&gt;
  
  
  4. La Catena dei Timeout: Sincronia Proxy-Backend
&lt;/h1&gt;

&lt;p&gt;Se proxy e backend non sono coordinati, i worker restano occupati inutilmente.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Regola fondamentale: l’applicazione deve morire prima del proxy.&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parametro&lt;/th&gt;
&lt;th&gt;Proxy&lt;/th&gt;
&lt;th&gt;Backend&lt;/th&gt;
&lt;th&gt;Note&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;KeepAliveTimeout&lt;/td&gt;
&lt;td&gt;3s&lt;/td&gt;
&lt;td&gt;5s&lt;/td&gt;
&lt;td&gt;Il backend aspetta di più&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Timeout&lt;/td&gt;
&lt;td&gt;60s&lt;/td&gt;
&lt;td&gt;65s&lt;/td&gt;
&lt;td&gt;Ricezione dati&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ProxyTimeout&lt;/td&gt;
&lt;td&gt;300s&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;Attesa risposta backend&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PHP max_execution_time&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;290s&lt;/td&gt;
&lt;td&gt;L’app muore prima del proxy&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h1&gt;
  
  
  5. Configurazione Globale dei Timeout (operativa)
&lt;/h1&gt;

&lt;p&gt;Creare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/etc/apache2/conf-available/global-timeouts.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apache"&gt;&lt;code&gt;&lt;span class="nc"&gt;KeepAlive&lt;/span&gt; &lt;span class="ss"&gt;On&lt;/span&gt;
&lt;span class="nc"&gt;MaxKeepAliveRequests&lt;/span&gt; 100
&lt;span class="nc"&gt;KeepAliveTimeout&lt;/span&gt; 3

&lt;span class="nc"&gt;Timeout&lt;/span&gt; 60
&lt;span class="nc"&gt;ProxyTimeout&lt;/span&gt; 300
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Attivare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;a2enconf global-timeouts
systemctl reload apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Questo file evita configurazioni duplicate nei VirtualHost.&lt;/p&gt;




&lt;h1&gt;
  
  
  6. Bilanciamento e Failover Rapido
&lt;/h1&gt;

&lt;p&gt;Il failover lento è uno dei problemi più comuni nei proxy Apache.&lt;/p&gt;

&lt;p&gt;Usiamo &lt;code&gt;connectiontimeout&lt;/code&gt; per forzare il rilevamento immediato dei nodi down.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apache"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nl"&gt;Proxy&lt;/span&gt;&lt;span class="sr"&gt; "balancer://app_cluster"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="nc"&gt;BalancerMember&lt;/span&gt; "http://node01:8080" route=n1 connectiontimeout=2 retry=30
    &lt;span class="nc"&gt;BalancerMember&lt;/span&gt; "http://node02:8080" route=n2 connectiontimeout=2 retry=30
    &lt;span class="nc"&gt;ProxySet&lt;/span&gt; lbmethod=bybusyness timeout=60
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nl"&gt;Proxy&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Con questo:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;un nodo morto viene escluso in ~2 secondi&lt;/li&gt;
&lt;li&gt;il traffico migra subito sugli altri&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  7. Separare traffico veloce e lento
&lt;/h1&gt;

&lt;p&gt;Questa tecnica serve a proteggere le richieste normali da quelle pesanti.&lt;/p&gt;

&lt;p&gt;È corretta &lt;strong&gt;solo se il backend lento ha risorse dedicate&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apache"&gt;&lt;code&gt;&lt;span class="c"&gt;# Pool veloce&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nl"&gt;Proxy&lt;/span&gt;&lt;span class="sr"&gt; "balancer://app_fast"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="nc"&gt;BalancerMember&lt;/span&gt; "http://app:8080" connectiontimeout=2
    &lt;span class="nc"&gt;ProxySet&lt;/span&gt; timeout=60
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nl"&gt;Proxy&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="c"&gt;# Pool lento&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nl"&gt;Proxy&lt;/span&gt;&lt;span class="sr"&gt; "balancer://app_slow"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="nc"&gt;BalancerMember&lt;/span&gt; "http://app_dedicated:8080" connectiontimeout=2
    &lt;span class="nc"&gt;ProxySet&lt;/span&gt; timeout=1200
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nl"&gt;Proxy&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Se entrambi puntano allo stesso backend, non serve a nulla.&lt;/p&gt;




&lt;h1&gt;
  
  
  8. PHP-FPM: il vero limite della capacità
&lt;/h1&gt;

&lt;p&gt;Apache accetta la richiesta, ma PHP la esegue.&lt;/p&gt;

&lt;p&gt;Per 4 GB con 2 GB dedicati a PHP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pm.max_children ≈ RAM_php / memoria_media_script
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configurazione:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/etc/php/8.x/fpm/pool.d/www.conf&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="py"&gt;pm&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;dynamic&lt;/span&gt;
&lt;span class="py"&gt;pm.max_children&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;40&lt;/span&gt;
&lt;span class="py"&gt;pm.start_servers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;10&lt;/span&gt;
&lt;span class="py"&gt;pm.max_requests&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;500&lt;/span&gt;
&lt;span class="py"&gt;request_terminate_timeout&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;300s&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Se PHP si satura, Apache sembra lento anche se non lo è.&lt;/p&gt;




&lt;h1&gt;
  
  
  9. Quando il tuning non basta: strategie architetturali
&lt;/h1&gt;

&lt;p&gt;Il tuning dei timeout migliora la stabilità, ma non cambia il modello di carico.&lt;/p&gt;

&lt;p&gt;Le operazioni lunghe dovrebbero diventare asincrone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Soluzioni tipiche
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;code con &lt;strong&gt;Redis&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;code con &lt;strong&gt;RabbitMQ&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;job worker separati&lt;/li&gt;
&lt;li&gt;risposta immediata “presa in carico”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Questo libera i worker Apache in pochi millisecondi.&lt;/p&gt;




&lt;h1&gt;
  
  
  10. Checklist finale operativa
&lt;/h1&gt;

&lt;p&gt;✔ TasksMax aumentato e verificato&lt;br&gt;
✔ MPM Event dimensionato sulla RAM&lt;br&gt;
✔ Timeout coerenti tra proxy, backend e PHP&lt;br&gt;
✔ Failover rapido con connectiontimeout&lt;br&gt;
✔ Backend lento separato solo se realmente isolato&lt;br&gt;
✔ PHP-FPM dimensionato sulla RAM reale&lt;br&gt;
✔ Monitoraggio periodico dei pids Apache&lt;/p&gt;




&lt;h1&gt;
  
  
  Conclusione
&lt;/h1&gt;

&lt;p&gt;La stabilità di un reverse proxy Apache non dipende da un singolo parametro, ma dall'allineamento di:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;limiti del sistema operativo&lt;/li&gt;
&lt;li&gt;modello di concorrenza di Apache&lt;/li&gt;
&lt;li&gt;timeout della catena proxy-backend&lt;/li&gt;
&lt;li&gt;capacità reale dell’applicazione&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quando questi quattro livelli sono coerenti, Apache diventa estremamente stabile anche sotto carico elevato.&lt;/p&gt;




</description>
      <category>devops</category>
      <category>performance</category>
      <category>security</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Eseguire Backup grandi su Debian: Compressione, Split e Sessioni Persistenti</title>
      <dc:creator>minnogit</dc:creator>
      <pubDate>Fri, 23 Jan 2026 15:52:34 +0000</pubDate>
      <link>https://dev.to/minnogit/eseguire-backup-grandi-su-debian-compressione-split-e-sessioni-persistenti-17c7</link>
      <guid>https://dev.to/minnogit/eseguire-backup-grandi-su-debian-compressione-split-e-sessioni-persistenti-17c7</guid>
      <description>&lt;p&gt;Gestire dataset massivi (100GB+) su un server remoto presenta due sfide principali: la &lt;strong&gt;gestione delle risorse&lt;/strong&gt; (RAM/CPU) e la &lt;strong&gt;stabilità della connessione&lt;/strong&gt;. Se la sessione SSH cade mentre stai creando un archivio enorme, il processo viene interrotto bruscamente, obbligandoti a ricominciare da capo.&lt;/p&gt;

&lt;p&gt;In questa guida vedremo come usare &lt;code&gt;7-Zip&lt;/code&gt; per creare archivi multi-volume e come proteggere il processo con &lt;code&gt;screen&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Il problema della disconnessione SSH
&lt;/h2&gt;

&lt;p&gt;Quando avvii un comando tramite SSH, questo è legato alla tua sessione. Se la tua connessione internet vacilla o chiudi il terminale, il sistema invia un segnale di "hangup" (SIGHUP) e interrompe il lavoro. Per un backup di molto grande che può richiedere ore, questo è un rischio inaccettabile.&lt;/p&gt;

&lt;h3&gt;
  
  
  La soluzione: GNU Screen
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;screen&lt;/code&gt; è un multiplexer di terminale che permette di avviare un processo in una sessione virtuale che sopravvive anche se ti disconnetti.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installazione:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;screen p7zip-full

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  2. Flusso di lavoro con Screen
&lt;/h2&gt;

&lt;p&gt;Prima di lanciare il comando di compressione, crea una sessione dedicata:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Crea una sessione:&lt;/strong&gt; &lt;code&gt;screen -S backup_cliente&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lancia il comando di compressione&lt;/strong&gt; (vedi sezione successiva).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scollegati (Detach):&lt;/strong&gt; Premi &lt;code&gt;CTRL + A&lt;/code&gt; e poi il tasto &lt;code&gt;D&lt;/code&gt;. Ora puoi chiudere il terminale e spegnere il tuo PC; il server continuerà a lavorare.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ricollegati (Resume):&lt;/strong&gt; Quando vuoi controllare l'avanzamento, torna nel terminale e scrivi:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;screen &lt;span class="nt"&gt;-r&lt;/span&gt; backup_cliente

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  3. Il comando 7-Zip ottimizzato (Low RAM)
&lt;/h2&gt;

&lt;p&gt;Per evitare che il server vada in crash per esaurimento memoria (OOM Error), utilizziamo parametri che limitano l'uso della RAM e della CPU:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;7z a &lt;span class="nt"&gt;-v1g&lt;/span&gt; &lt;span class="nt"&gt;-mx&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="nt"&gt;-md&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;16m &lt;span class="nt"&gt;-mmt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2 &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nt"&gt;-mhe&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;on archive_name.7z ./source_folder/

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Analisi dei parametri:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;a&lt;/code&gt;&lt;/strong&gt;: Aggiunge i file all'archivio.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-v1g&lt;/code&gt;&lt;/strong&gt;: Divide l'archivio in parti da &lt;strong&gt;1GB&lt;/strong&gt; (ideale per upload/download FTP stabili).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-mx=1&lt;/code&gt;&lt;/strong&gt;: Compressione minima (ultra-rapida). Fondamentale per risparmiare tempo.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-md=16m&lt;/code&gt;&lt;/strong&gt;: Riduce il "dizionario" di compressione a 16MB per mantenere basso l'uso della RAM.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-mmt=2&lt;/code&gt;&lt;/strong&gt;: Limita l'uso a 2 thread della CPU.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-p&lt;/code&gt;&lt;/strong&gt;: Richiede una password in modo sicuro (non apparirà in chiaro nei log).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-mhe=on&lt;/code&gt;&lt;/strong&gt;: Cifra anche i nomi dei file (senza password non si vede il contenuto).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Verifica e Consegna al Cliente
&lt;/h2&gt;

&lt;p&gt;Una volta terminato, verifica l'integrità dei volumi prima di caricarli sull'FTP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;7z t archive_name.7z.001

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Istruzioni per il cliente:&lt;/strong&gt;&lt;br&gt;
Comunica al destinatario che per estrarre i dati dovrà:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Scaricare &lt;strong&gt;tutti&lt;/strong&gt; i file (&lt;code&gt;.001&lt;/code&gt;, &lt;code&gt;.002&lt;/code&gt;, ... fino al file &lt;code&gt;.7z&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Usare software come &lt;strong&gt;7-Zip&lt;/strong&gt; (Windows).&lt;/li&gt;
&lt;li&gt;Aprire esclusivamente il primo file della serie; il programma ricomporrà automaticamente l'intero archivio.&lt;/li&gt;
&lt;/ol&gt;




</description>
      <category>linux</category>
    </item>
    <item>
      <title>Ripristinare il backup di un database PostgreSQL su AWS senza accesso diretto al server DB</title>
      <dc:creator>minnogit</dc:creator>
      <pubDate>Tue, 20 Jan 2026 18:25:27 +0000</pubDate>
      <link>https://dev.to/minnogit/ripristinare-il-backup-di-un-database-postgresql-su-aws-senza-accesso-diretto-al-server-db-3gf0</link>
      <guid>https://dev.to/minnogit/ripristinare-il-backup-di-un-database-postgresql-su-aws-senza-accesso-diretto-al-server-db-3gf0</guid>
      <description>&lt;p&gt;In molte infrastrutture AWS ben progettate, il server PostgreSQL &lt;strong&gt;non è esposto su Internet&lt;/strong&gt;:&lt;br&gt;
non ha un IP pubblico statico e &lt;strong&gt;non è accessibile direttamente via SSH&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Il database risiede in una &lt;strong&gt;subnet privata&lt;/strong&gt; all’interno di una &lt;strong&gt;VPC&lt;/strong&gt;, mentre l’accesso avviene tramite un &lt;strong&gt;server ponte (jump host / bastion host)&lt;/strong&gt; con IP pubblico.&lt;/p&gt;

&lt;p&gt;In questo articolo vediamo &lt;strong&gt;come ripristinare un database PostgreSQL partendo da un file &lt;code&gt;.sql&lt;/code&gt; presente sul proprio PC&lt;/strong&gt;, analizzando &lt;strong&gt;le diverse soluzioni possibili&lt;/strong&gt;, i &lt;strong&gt;pro e contro&lt;/strong&gt;, e raccogliendo in fondo una serie di &lt;strong&gt;comandi PostgreSQL di uso comune&lt;/strong&gt; come note operative.&lt;/p&gt;


&lt;h2&gt;
  
  
  Scenario di riferimento
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PC locale&lt;/strong&gt;: Debian Linux, con file &lt;code&gt;db.sql&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server ponte&lt;/strong&gt;: accessibile via SSH con chiave (&lt;code&gt;serverponte.dominioaziendale.it&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Server PostgreSQL&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Debian&lt;/li&gt;
&lt;li&gt;IP privato statico (es. &lt;code&gt;serverpostgresql.ipprivato.domioaziendale.it&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Accessibile solo dalla VPC&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Utenti DB disponibili&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;postgres&lt;/code&gt; (superuser)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;admin&lt;/code&gt; (utente applicativo)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Obiettivo&lt;/strong&gt;: ripristinare il database &lt;code&gt;NomeDB&lt;/code&gt; da script SQL&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Problema tipico
&lt;/h2&gt;

&lt;p&gt;Lo script SQL &lt;strong&gt;non viene eseguito correttamente usando DBeaver&lt;/strong&gt; con l’utente &lt;code&gt;admin&lt;/code&gt; e produce errori come:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;permessi insufficienti&lt;/li&gt;
&lt;li&gt;impossibilità di creare estensioni&lt;/li&gt;
&lt;li&gt;errori su &lt;code&gt;OWNER TO postgres&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;messaggi legati a &lt;code&gt;pg_hba.conf&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Questo accade perché &lt;strong&gt;un file &lt;code&gt;.sql&lt;/code&gt; spesso contiene operazioni da superuser&lt;/strong&gt;, anche se il database esiste già.&lt;/p&gt;


&lt;h2&gt;
  
  
  Le possibili soluzioni
&lt;/h2&gt;
&lt;h3&gt;
  
  
  ✔️ Soluzione 1 – Tunnel SSH + &lt;code&gt;psql&lt;/code&gt; locale (consigliata)
&lt;/h3&gt;

&lt;p&gt;È la soluzione &lt;strong&gt;più pulita, sicura e professionale&lt;/strong&gt;.&lt;br&gt;
Non richiede di copiare file sui server e sfrutta il port forwarding SSH.&lt;/p&gt;
&lt;h3&gt;
  
  
  Schema logico
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PC locale → tunnel SSH → server ponte → rete privata → PostgreSQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Apertura del tunnel
&lt;/h3&gt;

&lt;p&gt;Dal &lt;strong&gt;PC locale&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-L&lt;/span&gt; 5433:serverpostgresql.ipprivato.domioaziendale.it:5432 serverponte.dominioaziendale.it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;5433&lt;/code&gt; → porta locale&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;5432&lt;/code&gt; → porta PostgreSQL remota&lt;/li&gt;
&lt;li&gt;il tunnel resta attivo finché la sessione SSH è aperta&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Ripristino del database
&lt;/h3&gt;

&lt;p&gt;In un &lt;strong&gt;secondo terminale locale&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;psql &lt;span class="nt"&gt;-h&lt;/span&gt; localhost &lt;span class="nt"&gt;-p&lt;/span&gt; 5433 &lt;span class="nt"&gt;-U&lt;/span&gt; admin &lt;span class="nt"&gt;-d&lt;/span&gt; NomeDB &amp;lt; db.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⚠️ In questo scenario l’utente &lt;code&gt;admin&lt;/code&gt; &lt;strong&gt;deve essere SUPERUSER&lt;/strong&gt;, altrimenti lo script potrebbe fallire.&lt;/p&gt;




&lt;h3&gt;
  
  
  ✔️ Soluzione 2 – Promuovere temporaneamente &lt;code&gt;admin&lt;/code&gt; a superuser
&lt;/h3&gt;

&lt;p&gt;Se &lt;code&gt;pg_hba.conf&lt;/code&gt; blocca le connessioni dell’utente &lt;code&gt;postgres&lt;/code&gt; da remoto (caso molto comune in ambienti gestiti con Puppet), la soluzione più pragmatica è:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;USER&lt;/span&gt; &lt;span class="k"&gt;admin&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;SUPERUSER&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dopo il ripristino:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;USER&lt;/span&gt; &lt;span class="k"&gt;admin&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;NOSUPERUSER&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✔️ Veloce&lt;br&gt;
✔️ Non richiede modifiche a &lt;code&gt;pg_hba.conf&lt;/code&gt;&lt;br&gt;
✔️ Adatta a interventi manuali controllati&lt;/p&gt;


&lt;h3&gt;
  
  
  ✔️ Soluzione 3 – Copiare il file sul server DB ed eseguire localmente
&lt;/h3&gt;

&lt;p&gt;Indicata per file molto grandi o connessioni instabili.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;scp db.sql serverponte.dominioaziendale.it:/tmp/
&lt;span class="c"&gt;# poi dal jump host verso il DB&lt;/span&gt;
scp /tmp/db.sql serverpostgresql.ipprivato.domioaziendale.it:/tmp/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sul server DB:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;su - postgres
psql NomeDB &amp;lt; /tmp/db.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✔️ Massima affidabilità&lt;br&gt;
❌ Più passaggi manuali&lt;/p&gt;


&lt;h2&gt;
  
  
  Perché DBeaver spesso non basta
&lt;/h2&gt;

&lt;p&gt;DBeaver funziona bene per:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;restore da dump binari&lt;/li&gt;
&lt;li&gt;operazioni standard&lt;/li&gt;
&lt;li&gt;utenti applicativi&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ma &lt;strong&gt;fallisce con script SQL complessi&lt;/strong&gt; che contengono:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;CREATE EXTENSION&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ALTER OWNER&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SET ROLE&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;operazioni su schemi di sistema&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 In questi casi &lt;code&gt;psql&lt;/code&gt; è lo strumento giusto.&lt;/p&gt;


&lt;h2&gt;
  
  
  Note operative – Comandi PostgreSQL di uso comune
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Creare un database
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;NomeDB&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Creare una copia da un database esistente
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;testCopia&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="k"&gt;TEMPLATE&lt;/span&gt; &lt;span class="s1"&gt;'NomeDB'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Assegnare tutti i permessi a un utente
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;GRANT&lt;/span&gt; &lt;span class="k"&gt;ALL&lt;/span&gt; &lt;span class="k"&gt;PRIVILEGES&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;NomeDB&lt;/span&gt; &lt;span class="k"&gt;TO&lt;/span&gt; &lt;span class="k"&gt;admin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Collegarsi a un database con un utente specifico
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;psql &lt;span class="nt"&gt;-U&lt;/span&gt; admin &lt;span class="nt"&gt;-d&lt;/span&gt; NomeDB &lt;span class="nt"&gt;-h&lt;/span&gt; localhost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Eliminare un database
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;psql &lt;span class="nt"&gt;-U&lt;/span&gt; postgresql &lt;span class="nt"&gt;-h&lt;/span&gt; localhost
DROP DATABASE database_da_eliminare WITH &lt;span class="o"&gt;(&lt;/span&gt;FORCE&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Backup con &lt;code&gt;pg_dump&lt;/code&gt;
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Creare un dump SQL
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pg_dump &lt;span class="nt"&gt;-f&lt;/span&gt; /tmp/nome_database_dump.sql &lt;span class="nt"&gt;-U&lt;/span&gt; postgres &lt;span class="nt"&gt;-W&lt;/span&gt; nome_database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Significato opzioni:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-f&lt;/code&gt; → file di output&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-U postgres&lt;/code&gt; → utente DB&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-W&lt;/code&gt; → richiede password&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;nome_database&lt;/code&gt; → nome database&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Evitare la richiesta password (automazioni)
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Metodo consigliato: &lt;code&gt;.pgpass&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;File &lt;code&gt;~/.pgpass&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hostname:port:database:username:password
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Permessi obbligatori:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;600 ~/.pgpass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Metodo rapido (meno sicuro)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PGPASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'password'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Ripristino di un database PostgreSQL: scegliere il comando giusto
&lt;/h2&gt;

&lt;p&gt;Il comando da usare per il ripristino &lt;strong&gt;dipende dal formato del backup&lt;/strong&gt;, ovvero da &lt;strong&gt;come è stato creato con &lt;code&gt;pg_dump&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;È un aspetto fondamentale: usare lo strumento sbagliato porta a errori o a ripristini incompleti.&lt;/p&gt;




&lt;h3&gt;
  
  
  1️⃣ Ripristino da file SQL (Plain Text)
&lt;/h3&gt;

&lt;p&gt;Se il backup è stato creato &lt;strong&gt;senza opzioni di formato&lt;/strong&gt; (output leggibile, &lt;code&gt;.sql&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pg_dump nome_database &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; backup.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;oppure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pg_dump &lt;span class="nt"&gt;-f&lt;/span&gt; /tmp/pnd_dump.sql nome_database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;il ripristino va fatto &lt;strong&gt;con &lt;code&gt;psql&lt;/code&gt;&lt;/strong&gt;, che esegue sequenzialmente le istruzioni SQL contenute nel file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;psql &lt;span class="nt"&gt;-U&lt;/span&gt; postgres &lt;span class="nt"&gt;-d&lt;/span&gt; nome_database &lt;span class="nt"&gt;-f&lt;/span&gt; /tmp/nome_database_dump.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note importanti:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Il database di destinazione &lt;strong&gt;deve già esistere&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Il file è leggibile e modificabile&lt;/li&gt;
&lt;li&gt;Su database molto grandi può essere più lento&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  2️⃣ Ripristino da file Custom o Directory (&lt;code&gt;.dump&lt;/code&gt;, &lt;code&gt;.bak&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Se il backup è stato creato con:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pg_dump &lt;span class="nt"&gt;-Fc&lt;/span&gt; nome_database &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; backup.dump
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;oppure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pg_dump &lt;span class="nt"&gt;-Fd&lt;/span&gt; nome_database &lt;span class="nt"&gt;-f&lt;/span&gt; backup_dir
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;si tratta di un &lt;strong&gt;formato binario/speciale&lt;/strong&gt;, che &lt;strong&gt;non può essere eseguito con &lt;code&gt;psql&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In questo caso va usato &lt;strong&gt;&lt;code&gt;pg_restore&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pg_restore &lt;span class="nt"&gt;-U&lt;/span&gt; postgres &lt;span class="nt"&gt;-d&lt;/span&gt; nome_database &lt;span class="nt"&gt;-v&lt;/span&gt; backup.dump
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Opzioni utili:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-v&lt;/code&gt; → modalità verbose&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--clean&lt;/code&gt; → elimina gli oggetti prima di ricrearli&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--if-exists&lt;/code&gt; → evita errori se gli oggetti non esistono&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Ripristino in parallelo (solo con &lt;code&gt;pg_restore&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Uno dei grandi vantaggi dei formati custom o directory è la possibilità di usare &lt;strong&gt;più core CPU&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pg_restore &lt;span class="nt"&gt;-j&lt;/span&gt; 4 &lt;span class="nt"&gt;-U&lt;/span&gt; postgres &lt;span class="nt"&gt;-d&lt;/span&gt; nome_database backup.dump
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Ideale per database grandi in ambienti server.&lt;/p&gt;




&lt;h3&gt;
  
  
  Tabella rapida di riferimento
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Formato backup&lt;/th&gt;
&lt;th&gt;Strumento&lt;/th&gt;
&lt;th&gt;Quando usarlo&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;.sql&lt;/code&gt; (plain text)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;psql&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Backup leggibile, semplice&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;.dump&lt;/code&gt; (custom)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;pg_restore&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Backup compresso, selettivo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;directory&lt;/td&gt;
&lt;td&gt;&lt;code&gt;pg_restore&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ripristino veloce e parallelo&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  Nota operativa importante
&lt;/h3&gt;

&lt;p&gt;Se il database di destinazione è &lt;strong&gt;già in uso&lt;/strong&gt;, il ripristino può fallire per:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;connessioni attive&lt;/li&gt;
&lt;li&gt;oggetti già esistenti&lt;/li&gt;
&lt;li&gt;lock sulle tabelle&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In questi casi è consigliabile:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ripristinare su un database vuoto&lt;/li&gt;
&lt;li&gt;oppure usare &lt;code&gt;--clean&lt;/code&gt; con attenzione&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusione
&lt;/h2&gt;

&lt;p&gt;In ambienti AWS con PostgreSQL in subnet private:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;non si espone mai il DB su Internet&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;il jump host è la chiave&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;psql&lt;/code&gt; è lo strumento più affidabile&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;i permessi contano più della GUI&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il &lt;strong&gt;tunnel SSH + &lt;code&gt;psql&lt;/code&gt;&lt;/strong&gt; resta la soluzione più solida, ripetibile e sicura per ripristinare database PostgreSQL in infrastrutture cloud ben progettate.&lt;/p&gt;




</description>
      <category>postgressql</category>
      <category>linux</category>
    </item>
    <item>
      <title>Inizializzare GIT e configurare autenticazione SSH GitHub</title>
      <dc:creator>minnogit</dc:creator>
      <pubDate>Thu, 08 May 2025 08:54:46 +0000</pubDate>
      <link>https://dev.to/minnogit/inizializzare-git-4pfd</link>
      <guid>https://dev.to/minnogit/inizializzare-git-4pfd</guid>
      <description>&lt;p&gt;git --version&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global color.ui true
git config --global user.name 'Mario Rossi'
git config --global user.email emailAccount

git config --global core.editor nano
O questo per usare vscode:
git config --global core.editor "code --wait"

git config --global gui.editor gedit
git config --global init.defaultBranch main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Se non si mette &lt;code&gt;--global&lt;/code&gt; la configurazione sarà relativa al repository.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent" rel="noopener noreferrer"&gt;Creare chiave ssh&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -t ed25519 -C "your_email@example.com"
cat ~/.ssh/id_ed25519_sk.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Aggiungere al profilo &lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account" rel="noopener noreferrer"&gt;Github&lt;/a&gt; la chiave pubblica.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository" rel="noopener noreferrer"&gt;Clonare il repository con ssh&lt;/a&gt;&lt;br&gt;
Ad es.: &lt;code&gt;git clone git@github.com:organizzazione/progetto.git&lt;/code&gt;&lt;br&gt;
Si può fare anche da &lt;a href="https://code.visualstudio.com/docs/sourcecontrol/github" rel="noopener noreferrer"&gt;VSCode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Se si ottiene errore &lt;code&gt;Permission denied (publickey)&lt;/code&gt; vuol dire che il comando git non trova o non può usare la chiave SSH per parlare con GitHub.&lt;br&gt;
Mi è successo in ambiente di sviluppo Dev Container con Docker Rootless in cui il Dev Container cerca di passare le chiavi dall'host al container.&lt;br&gt;
Per risolvere, verificare se l'agente SSH è vivo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$SSH_AUTH_SOCK&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Se l'output è vuoto: VS Code non sta passando l'agente SSH al container.&lt;br&gt;
Se vedi un percorso (es. /tmp/vscode-ssh-auth...): L'agente è passato, ma dobbiamo vedere se possiamo usarlo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-add &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Se dice "The agent has no identities": L'agente è collegato ma "vuoto" (devi fare &lt;code&gt;ssh-add&lt;/code&gt; sul tuo host Linux).&lt;/p&gt;

&lt;p&gt;Verificare la connessione con &lt;code&gt;ssh -vT git@github.com&lt;/code&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Elenco in Conky di applicazioni con l'uso della swap</title>
      <dc:creator>minnogit</dc:creator>
      <pubDate>Thu, 20 Apr 2023 15:30:00 +0000</pubDate>
      <link>https://dev.to/minnogit/elenco-in-conky-di-applicazioni-con-luso-della-swap-5af7</link>
      <guid>https://dev.to/minnogit/elenco-in-conky-di-applicazioni-con-luso-della-swap-5af7</guid>
      <description>&lt;p&gt;In continuazione del precedente post, adesso vediamo come stampare in Conky un elenco di programmi con la relativa quantità di swap usata.&lt;/p&gt;

&lt;p&gt;Prepariamo uno script bash che restituisce il testo che vogliamo visualizzare in Conky basato sul comando spiegato in precedenza ma con una differenza in particolare: ci possono essere più processi in esecuzione dello spesso comando (ad esempio 5 processi per Chrome) ma quello che voglio visualizzare in Conky, è la somma della swap usata da tutti i processi dello stesso comando.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;unioneTest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; /proc/&lt;span class="k"&gt;*&lt;/span&gt;/status&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
  if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'/^(Name:)/ {awk_name=$2} /^(VmSwap:)/ {awk_vmswap=$2" "$3} /^(Pid:)/ {awk_pid=$2} END { if (awk_vmswap &amp;amp;&amp;amp; substr(awk_vmswap,1,1) != '&lt;/span&gt;0&lt;span class="s1"&gt;' ) print awk_name" "awk_pid" "awk_vmswap}'&lt;/span&gt; &lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$test&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
      &lt;/span&gt;unioneTest+&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$test&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;fi
  fi
done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A differenza del comando precedente, alla fine dell'analisi awk di ogni file, viene verificato se la variabile &lt;em&gt;awk_vmswap&lt;/em&gt; non è vuota e se il primo carattere non è "0". Se queste condizioni sono soddisfatte, viene creato un nuovo record di informazioni sul processo, che viene memorizzato nella variabile &lt;em&gt;test&lt;/em&gt;.&lt;br&gt;
Se la variabile &lt;em&gt;test&lt;/em&gt; non è vuota, viene aggiunto alla variabile &lt;em&gt;unioneTest&lt;/em&gt; e viene inserito un carattere di nuova linea ("\n") per separare i record.&lt;br&gt;
Alla fine, &lt;em&gt;$unioneTest&lt;/em&gt; conterrà l'elenco dei processi che usano la swap.&lt;/p&gt;

&lt;p&gt;Il passo successivo, è sommare tra loro i valori di swap degli stessi comandi.&lt;br&gt;
Per farlo, creo un array associativo denominato &lt;em&gt;somma&lt;/em&gt; mediante il comando &lt;code&gt;declare -A&lt;/code&gt;.&lt;br&gt;
Questo array verrà utilizzato per accumulare i valori della terza colonna (ovvero la quantità di swap usata) dei processi che hanno lo stesso nome.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;dati&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$unioneTest&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; somma

&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; linea&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
  &lt;/span&gt;&lt;span class="nv"&gt;nome&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$linea&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt; &lt;span class="nt"&gt;-f1&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
  &lt;span class="nv"&gt;valore&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$linea&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt; &lt;span class="nt"&gt;-f3&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
  &lt;span class="o"&gt;((&lt;/span&gt;somma[&lt;span class="nv"&gt;$nome&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; +&lt;span class="o"&gt;=&lt;/span&gt; valore&lt;span class="o"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$unioneTest&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Il ciclo &lt;em&gt;while&lt;/em&gt; viene alimentato con un &lt;a href="https://tldp.org/LDP/abs/html/x17837.html" rel="noopener noreferrer"&gt;here-string&lt;/a&gt; (&amp;lt;&amp;lt;&amp;lt;) che contiene l'output di un comando &lt;em&gt;echo -e&lt;/em&gt; che converte una stringa contenente i dati da elaborare.&lt;/p&gt;

&lt;p&gt;Infine, stampiamo l'elenco dall'array &lt;em&gt;somma&lt;/em&gt; inserendo in ogni riga il numero di spazi necessario ad avere una lunghezza prestabilita. Gli spazi vengono inseriti tra il nome del comando e la quantità di swap usata.&lt;br&gt;
La lunghezza delle righe, verrà specificata da un parametro dello script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;elenco&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;nome &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="p"&gt;!somma[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nv"&gt;tmp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$nome&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;somma&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$nome&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; kB&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nv"&gt;nrSpacesToAdd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;expr&lt;/span&gt; &lt;span class="nv"&gt;$spaces&lt;/span&gt; - &lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;tmp&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
    elenco+&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$nome&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%*s'&lt;/span&gt; &lt;span class="nv"&gt;$nrSpacesToAdd&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;somma&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$nome&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; kB&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;done
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$elenco&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-k&lt;/span&gt; 2 &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;nrSpacesToAdd&lt;/em&gt; calcola il numero di spazi da aggiungere ad una stringa, in modo da ottenere una stringa di una lunghezza specifica.&lt;br&gt;
La variabile &lt;em&gt;$spaces&lt;/em&gt; rappresenta il numero totale di spazi che si desidera avere nella stringa finale.&lt;br&gt;
La variabile &lt;em&gt;${#tmp}&lt;/em&gt; rappresenta la lunghezza della stringa &lt;em&gt;tmp&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;(printf '%*s' $nrSpacesToAdd)&lt;/code&gt; viene utilizzato per generare una stringa di spazi della lunghezza &lt;em&gt;$nrSpacesToAdd&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Questo è lo script completo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$# &lt;/span&gt;&lt;span class="nt"&gt;-eq&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Specificare la lunghezza delle stringhe"&lt;/span&gt;
  &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="c"&gt;# Lunghezza voluta delle stringhe&lt;/span&gt;
&lt;span class="nv"&gt;spaces&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;

&lt;span class="nv"&gt;unioneTest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; /proc/&lt;span class="k"&gt;*&lt;/span&gt;/status&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
  if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'/^(Name:)/ {awk_name=$2} /^(VmSwap:)/ {awk_vmswap=$2" "$3} /^(Pid:)/ {awk_pid=$2} END { if (awk_vmswap &amp;amp;&amp;amp; substr(awk_vmswap,1,1) != '&lt;/span&gt;0&lt;span class="s1"&gt;' ) print awk_name" "awk_pid" "awk_vmswap}'&lt;/span&gt; &lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$test&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
      &lt;/span&gt;unioneTest+&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$test&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;fi
  fi
done

if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$unioneTest&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nv"&gt;dati&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$unioneTest&lt;/span&gt;
  &lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; somma

  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; linea&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nv"&gt;nome&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$linea&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt; &lt;span class="nt"&gt;-f1&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="nv"&gt;valore&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$linea&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt; &lt;span class="nt"&gt;-f3&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;((&lt;/span&gt;somma[&lt;span class="nv"&gt;$nome&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; +&lt;span class="o"&gt;=&lt;/span&gt; valore&lt;span class="o"&gt;))&lt;/span&gt;
  &lt;span class="k"&gt;done&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$unioneTest&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

  &lt;span class="nv"&gt;elenco&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;nome &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="p"&gt;!somma[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nv"&gt;tmp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;" &lt;/span&gt;&lt;span class="nv"&gt;$nome&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;somma&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$nome&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; kB&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nv"&gt;nrSpacesToAdd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;expr&lt;/span&gt; &lt;span class="nv"&gt;$spaces&lt;/span&gt; - &lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;tmp&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
    elenco+&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$nome&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%*s'&lt;/span&gt; &lt;span class="nv"&gt;$nrSpacesToAdd&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;somma&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$nome&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; kB&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;done
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$elenco&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-k&lt;/span&gt; 2 &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Esempio di output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;./swapUsed.sh 41
java                           94708 kB
apache2                        16188 kB
gnome-software                  8792 kB
chrome                           632 kB
pipewire-pulse                   564 kB
dbus-launch                      452 kB
exim4                            388 kB
dbus-daemon                      388 kB
postgres                          72 kB
&lt;span class="o"&gt;(&lt;/span&gt;sd-pam&lt;span class="o"&gt;)&lt;/span&gt;                          64 kB
containerd                        60 kB
spotify                           52 kB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Per usare il comando in Conky, ho aggiunto al file di configurazione .conkyrc le seguenti linee nella sezione conky.text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
$hr
${color grey}Name                          Swap used
${color lightgrey}${execi 30 ~/swapUsed.sh 41 | head -n 10}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Questo fa si che il comando venga eseguito ogni 30 secondi con il parametro &lt;em&gt;41&lt;/em&gt; che specifica la lunghezza delle stringhe corretta per la mia configurazione Conky.&lt;br&gt;
Con &lt;code&gt;head -n 10&lt;/code&gt;, indico di stampare solo le prime 10 righe.&lt;/p&gt;

&lt;p&gt;Qui il file .conkyrc completo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- Conky, a system monitor https://github.com/brndnmtthws/conky
--
-- This configuration file is Lua code. You can write code in here, and it will
-- execute when Conky loads. You can use it to generate your own advanced
-- configurations.
--
-- Try this (remove the `--`):
--
--   print("Loading Conky config")
--
-- For more on Lua, see:
-- https://www.lua.org/pil/contents.html

conky.config = {
    alignment = 'top_right',
    background = false,
    border_width = 1,
    cpu_avg_samples = 2,
    default_color = 'white',
    default_outline_color = 'white',
    default_shade_color = 'white',
    double_buffer = true,
    draw_borders = false,
    draw_graph_borders = true,
    draw_outline = false,
    draw_shades = false,
    extra_newline = false,
    font = 'DejaVu Sans Mono:size=8',
    gap_x = 60,
    gap_y = 60,
    minimum_height = 5,
    minimum_width = 5,
    net_avg_samples = 2,
    no_buffers = true,
    out_to_console = false,
    out_to_ncurses = false,
    out_to_stderr = false,
    out_to_x = true,
    own_window = true,
    own_window_colour = '000000',
    own_window_class = 'Conky',
    own_window_type = 'desktop',
    own_window_transparent = true,
    own_window_argb_visual = true,
    own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
    show_graph_range = false,
    show_graph_scale = false,
    stippled_borders = 0,
    update_interval = 5.0,
    uppercase = false,
    use_spacer = 'none',
    use_xft = true,
}

conky.text = [[
${color grey}Uptime:$color $uptime
${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 8}
${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 8}
${color grey}CPU Usage:$color $cpu% ${cpubar 8}
${color grey}Processes:$color $processes  ${color grey}Running:$color $running_processes
$hr
${color grey}File systems:
 root $color${fs_used /}/${fs_size /} ${fs_bar 8 /}
 ec2-free $color${fs_free /mnt/ec2_export}/${fs_size /mnt/ec2_export} ${fs_bar 8 /mnt/ec2_export}
 qnap $color${fs_used /mnt/u_rsync}/${fs_size /mnt/u_rsync} ${fs_bar 8 /mnt/u_rsync}
${color grey}Networking:
Up:$color ${upspeed} ${color grey} - Down:$color ${downspeed}
$hr
${color grey}Name              PID     CPU%   MEM%
${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}
${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}
${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}
${color lightgrey} ${top name 5} ${top pid 5} ${top cpu 5} ${top mem 5}
$hr
${color grey}Name                          Swap used
${color lightgrey}${execi 30 ~/swapUsed.sh 41 | head -n 10}
]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv8gmaiepta7kxydr6cqq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv8gmaiepta7kxydr6cqq.png" alt=" " width="292" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Gestire la cache di npm e considerazioni per Docker</title>
      <dc:creator>minnogit</dc:creator>
      <pubDate>Mon, 17 Apr 2023 09:06:54 +0000</pubDate>
      <link>https://dev.to/minnogit/gestire-la-cache-di-npm-e-considerazioni-per-docker-8po</link>
      <guid>https://dev.to/minnogit/gestire-la-cache-di-npm-e-considerazioni-per-docker-8po</guid>
      <description>&lt;p&gt;Quando si richiede di installare un pacchetto npm, questo viene scaricato da internet e salvato nella cartella di cache, se non è già presente, e poi installato nell'applicazione che lo richiede.&lt;br&gt;
Dalla versione 5 di npm, la gestione della cache è &lt;em&gt;self-healing&lt;/em&gt; per cui dovrebbe riconoscere eventuali pacchetti incompleti, danneggiati o obsoleti e, in tal caso, scaricarli nuovamente cercando anche di risolvere automaticamente le dipendenze nel modo migliore.&lt;br&gt;
Tuttavia in alcuni casi, anche per risolvere problemi di installazione, è utile pulire la cache di npm con il comando:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nt"&gt;--global&lt;/span&gt; cache verify
Cache verified and compressed &lt;span class="o"&gt;(&lt;/span&gt;~/git/.npm/_cacache&lt;span class="o"&gt;)&lt;/span&gt;
Content verified: 9127 &lt;span class="o"&gt;(&lt;/span&gt;1525196266 bytes&lt;span class="o"&gt;)&lt;/span&gt;
Content garbage-collected: 3491 &lt;span class="o"&gt;(&lt;/span&gt;5398705346 bytes&lt;span class="o"&gt;)&lt;/span&gt;
Index entries: 9129
Finished &lt;span class="k"&gt;in &lt;/span&gt;34.248s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;La cartella della cache normalmente è &lt;code&gt;~/.npm&lt;/code&gt; (nell'es. sopra è &lt;code&gt;~/git/.npm&lt;/code&gt;) ma è possibile spostarla.&lt;br&gt;
Possono esserci diversi motivi per cui si potrebbe voler controllare il percorso della cache:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;la cartella può arrivare a occupare uno spazio considerevole e si potrebbe volerla spostare.&lt;/li&gt;
&lt;li&gt;si vuole usare una cartella di cache condivisa tra più host per velocizzare le installazioni.&lt;/li&gt;
&lt;li&gt;si vuole una cache condivisa tra gli utenti della stessa macchina.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Il comando per spostare la cartella di cache è:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm config &lt;span class="nb"&gt;set &lt;/span&gt;cache nuovaCartella &lt;span class="nt"&gt;--global&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Al posto di modificare la configurazione del file di configurazione di npm, è anche possibile impostare il percorso della cache in una variabile di ambiente:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;npm_config_cache&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/path/to/cache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dopo aver spostato la cache, lanciare il comando di verifica:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nt"&gt;--global&lt;/span&gt; cache verify&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;E' possibile vedere la configurazione attuale con il comando:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm config list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Il comando di verifica non cancella pacchetti scaricati ma non più usati, perciò si potrebbe voler cancellare tutta la cache con il comando:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm cache clean
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Considerazioni per Docker
&lt;/h2&gt;

&lt;p&gt;Se stiamo usando Docker, è possibile impostare la cartella della cache con:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;npm_config_cache&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/path/to/cache mydockerimage:tag
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In questo modo, il comando &lt;code&gt;docker run&lt;/code&gt; consente di eseguire un container Docker configurato per utilizzare una specifica directory per la cache dei pacchetti npm.&lt;br&gt;
Controllando dove i pacchetti vengono salvati, si può condividere la cache tra diversi container o host, ad esempio per ridurre il tempo di download dei pacchetti npm o per evitare di scaricare i pacchetti più volte.&lt;br&gt;
Inoltre, ci permette di usare la stessa cartella di cache anche quando si avvia il container con un utente diverso da quello attuale (ogni utente ha la sua cartella di cache).&lt;/p&gt;

</description>
      <category>npm</category>
      <category>docker</category>
      <category>linux</category>
    </item>
    <item>
      <title>Dividere il monitor in 4 terminali con Terminator</title>
      <dc:creator>minnogit</dc:creator>
      <pubDate>Thu, 13 Apr 2023 10:56:31 +0000</pubDate>
      <link>https://dev.to/minnogit/dividere-il-monitor-in-4-terminali-con-terminator-51ko</link>
      <guid>https://dev.to/minnogit/dividere-il-monitor-in-4-terminali-con-terminator-51ko</guid>
      <description>&lt;p&gt;Una delle prime cose che faccio quando la mattina entro nel pc al lavoro, è aprire alcuni terminali.&lt;/p&gt;

&lt;p&gt;Di solito uso &lt;a href="https://gnome-terminator.org/" rel="noopener noreferrer"&gt;Terminator&lt;/a&gt; che è un emulatore di terminale per Linux che consente di aprire e gestire più finestre di terminale all'interno di una sola finestra.&lt;br&gt;
Ha diverse caratteristiche interessanti, anche se la sua configurazione non è molto intuitiva per certi aspetti.&lt;/p&gt;

&lt;p&gt;La suddivisione in 4 terminali della finestra di Terminator è definita come un &lt;strong&gt;layout&lt;/strong&gt; nel suo file di configurazione.&lt;br&gt;
Ho quindi aggiunto un layout personalizzato &lt;em&gt;server&lt;/em&gt; dalla finestra delle preferenze.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fju7fgow3n4a0226hvyq1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fju7fgow3n4a0226hvyq1.png" alt="Terminator" width="800" height="666"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Si può anche modificare direttamente il file di configurazione:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;nano ~/.config/terminator/config

&lt;span class="o"&gt;[&lt;/span&gt;global_config]
  enabled_plugins &lt;span class="o"&gt;=&lt;/span&gt; CustomCommandsMenu, APTURLHandler
  suppress_multiple_term_dialog &lt;span class="o"&gt;=&lt;/span&gt; True
&lt;span class="o"&gt;[&lt;/span&gt;keybindings]
&lt;span class="o"&gt;[&lt;/span&gt;profiles]
  &lt;span class="o"&gt;[[&lt;/span&gt;default]]
    background_darkness &lt;span class="o"&gt;=&lt;/span&gt; 0.85
    font &lt;span class="o"&gt;=&lt;/span&gt; Monospace 9
    scrollback_lines &lt;span class="o"&gt;=&lt;/span&gt; 2000
    use_system_font &lt;span class="o"&gt;=&lt;/span&gt; False
&lt;span class="o"&gt;[&lt;/span&gt;layouts]
  &lt;span class="o"&gt;[[&lt;/span&gt;default]]
    &lt;span class="o"&gt;[[[&lt;/span&gt;child1]]]
      parent &lt;span class="o"&gt;=&lt;/span&gt; window0
      &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; Terminal
      &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
    &lt;span class="o"&gt;[[[&lt;/span&gt;window0]]]
      parent &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
      &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; Window
  &lt;span class="o"&gt;[[&lt;/span&gt;servers]]
    &lt;span class="o"&gt;[[[&lt;/span&gt;child0]]]
      &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; Window
      parent &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
      order &lt;span class="o"&gt;=&lt;/span&gt; 0
      position &lt;span class="o"&gt;=&lt;/span&gt; 0:0
      maximised &lt;span class="o"&gt;=&lt;/span&gt; True
      fullscreen &lt;span class="o"&gt;=&lt;/span&gt; False
      size &lt;span class="o"&gt;=&lt;/span&gt; 1920, 995
      title &lt;span class="o"&gt;=&lt;/span&gt; admin@node01: ~
      last_active_term &lt;span class="o"&gt;=&lt;/span&gt; 428ce1c8-9aed-4acf-a481-45a18c5f54a9
      last_active_window &lt;span class="o"&gt;=&lt;/span&gt; True
    &lt;span class="o"&gt;[[[&lt;/span&gt;child1]]]
      &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; HPaned
      parent &lt;span class="o"&gt;=&lt;/span&gt; child0
      order &lt;span class="o"&gt;=&lt;/span&gt; 0
      position &lt;span class="o"&gt;=&lt;/span&gt; 958
      ratio &lt;span class="o"&gt;=&lt;/span&gt; 0.5002610966057441
    &lt;span class="o"&gt;[[[&lt;/span&gt;child2]]]
      &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; VPaned
      parent &lt;span class="o"&gt;=&lt;/span&gt; child1
      order &lt;span class="o"&gt;=&lt;/span&gt; 0
      position &lt;span class="o"&gt;=&lt;/span&gt; 495
      ratio &lt;span class="o"&gt;=&lt;/span&gt; 0.5
    &lt;span class="o"&gt;[[[&lt;/span&gt;terminal3]]]
      &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; Terminal
      parent &lt;span class="o"&gt;=&lt;/span&gt; child2
      order &lt;span class="o"&gt;=&lt;/span&gt; 0
      profile &lt;span class="o"&gt;=&lt;/span&gt; default
      uuid &lt;span class="o"&gt;=&lt;/span&gt; a1b21c6d-82fa-4907-9b35-838b3743bb62
      &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
    &lt;span class="o"&gt;[[[&lt;/span&gt;terminal4]]]
      &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; Terminal
      parent &lt;span class="o"&gt;=&lt;/span&gt; child2
      order &lt;span class="o"&gt;=&lt;/span&gt; 1
      profile &lt;span class="o"&gt;=&lt;/span&gt; default
      uuid &lt;span class="o"&gt;=&lt;/span&gt; 9a8f88b6-22e6-49f4-865f-d100a84fa56e
      &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
    &lt;span class="o"&gt;[[[&lt;/span&gt;child5]]]
      &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; VPaned
      parent &lt;span class="o"&gt;=&lt;/span&gt; child1
      order &lt;span class="o"&gt;=&lt;/span&gt; 1
      position &lt;span class="o"&gt;=&lt;/span&gt; 496
      ratio &lt;span class="o"&gt;=&lt;/span&gt; 0.5
    &lt;span class="o"&gt;[[[&lt;/span&gt;terminal6]]]
      &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; Terminal
      parent &lt;span class="o"&gt;=&lt;/span&gt; child5
      order &lt;span class="o"&gt;=&lt;/span&gt; 0
      profile &lt;span class="o"&gt;=&lt;/span&gt; default
      uuid &lt;span class="o"&gt;=&lt;/span&gt; 716efc36-9385-4b79-898f-a437165c439b
      &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
    &lt;span class="o"&gt;[[[&lt;/span&gt;terminal7]]]
      &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; Terminal
      parent &lt;span class="o"&gt;=&lt;/span&gt; child5
      order &lt;span class="o"&gt;=&lt;/span&gt; 1
      profile &lt;span class="o"&gt;=&lt;/span&gt; default
      uuid &lt;span class="o"&gt;=&lt;/span&gt; 428ce1c8-9aed-4acf-a481-45a18c5f54a9
      &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;plugins]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adesso è possibile avviare Terminator specificando di usare il layout &lt;em&gt;server&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terminator &lt;span class="nt"&gt;--layout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;servers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Infine, ho creato un launcher apposito per gnome-shell con &lt;a href="https://github.com/bluesabre/menulibre" rel="noopener noreferrer"&gt;MenuLibre&lt;/a&gt; per eseguire il comando sopra.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnwclsfiso0zx6x65xs07.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnwclsfiso0zx6x65xs07.png" alt="MenuLibre" width="712" height="644"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>terminal</category>
      <category>linux</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Stampare un elenco dei processi ordinato per la quantità di swap che usano</title>
      <dc:creator>minnogit</dc:creator>
      <pubDate>Wed, 15 Mar 2023 22:21:24 +0000</pubDate>
      <link>https://dev.to/minnogit/stampare-un-elenco-dei-processi-ordinato-per-la-quantita-di-swap-che-usano-lmo</link>
      <guid>https://dev.to/minnogit/stampare-un-elenco-dei-processi-ordinato-per-la-quantita-di-swap-che-usano-lmo</guid>
      <description>&lt;p&gt;Cercando su internet possiamo trovare questo comando per stampare l'elenco dei processi ordinato per uso del file di Swap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; /proc/&lt;span class="k"&gt;*&lt;/span&gt;/status &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;&lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'/VmSwap|Name/{printf $2 " " $3}END{ print ""}'&lt;/span&gt; &lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-k&lt;/span&gt; 2 &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; | less
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Poiché per me è abbastanza magico, ho cercato di capire come funziona:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;for file in /proc/*/status&lt;/code&gt; - Ciclo su tutti i file di stato dei processi attualmente in esecuzione. La variabile "file" assume il valore di ogni percorso di file corrispondente.
Il contenuto del file di stato ad es. può essere:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; /proc/6377/status
Name:   gnome-software
Umask:  0022
State:  S &lt;span class="o"&gt;(&lt;/span&gt;sleeping&lt;span class="o"&gt;)&lt;/span&gt;
Tgid:   6377
Ngid:   0
Pid:    6377
PPid:   6154
TracerPid:  0
Uid:    1000    1000    1000    1000
Gid:    1000    1000    1000    1000
FDSize: 256
Groups: 24 25 27 29 30 33 44 46 106 109 112 114 999 1000 
NStgid: 6377
NSpid:  6377
NSpgid: 6154
NSsid:  6154
VmPeak:  2922312 kB
VmSize:  2791180 kB
VmLck:         0 kB
VmPin:         0 kB
VmHWM:    459088 kB
VmRSS:    163004 kB
RssAnon:      130664 kB
RssFile:       32340 kB
RssShmem:          0 kB
VmData:   621548 kB
VmStk:       728 kB
VmExe:       368 kB
VmLib:    184796 kB
VmPTE:      1384 kB
VmSwap:   218708 kB
HugetlbPages:          0 kB
CoreDumping:    0
THP_enabled:    1
Threads:    36
SigQ:   2/63374
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000001000
SigCgt: 0000000100000000
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 000001ffffffffff
CapAmb: 0000000000000000
NoNewPrivs: 0
Seccomp:    0
Seccomp_filters:    0
Speculation_Store_Bypass:   thread vulnerable
SpeculationIndirectBranch:  conditional enabled
Cpus_allowed:   f
Cpus_allowed_list:  0-3
Mems_allowed:   00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
Mems_allowed_list:  0
voluntary_ctxt_switches:    83533
nonvoluntary_ctxt_switches: 8663
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done&lt;/code&gt; - Per ogni percorso del file ($file), viene eseguito il comando awk. Il comando awk cerca le righe che contengono "VmSwap" o "Name" nel file di stato del processo e quindi utilizza il comando "printf" per stampare il secondo e il terzo campo di ogni riga. Nell' esempio del file di stato sopra, troviamo prima Name e poi VmSwap che verranno quindi trovati da awk in questo ordine. Quando la riga contiene Name, il secondo campo corrisponde al nome del processo e il terzo è vuoto. Quando la riga contiene VmSwap, il secondo campo contiene la memoria usata e il terzo l'unità di misura. Alla fine, la clausola "END" viene utilizzata per stampare una riga vuota per separare l'output dei diversi processi.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sort -k 2 -n -r&lt;/code&gt; - Ordina l'output in base al secondo campo (-k 2) in ordine numerico (-n) in ordine inverso (-r).&lt;br&gt;
Significa che la quantità di swap usata dai processi è ordinata dal più grande al più piccolo.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;less&lt;/code&gt; - Visualizzare l'output paginato nel terminale.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Es. di output del comando:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; /proc/&lt;span class="k"&gt;*&lt;/span&gt;/status &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;&lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'/VmSwap|Name/{printf $2 " " $3}END{ print ""}'&lt;/span&gt; &lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-k&lt;/span&gt; 2 &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; | less
gnome-software 218708 kB
mariadbd 155576 kB
code 147548 kB
code 134844 kB
firefox 111212 kB
WebExtensions 71236 kB
java 70472 kB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Se vogliamo aggiungere la stampa del Pid possiamo modificare il comando in questo modo:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;for file in /proc/*/status ; do awk '/^(VmSwap:|Name:|Pid:)/ {printf $2 " " $3}END{ print ""}' $file; done | sort -k 3 -n -r | less&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Adesso, il pattern di ricerca usa il carattere ^ che specifica che la corrispondenza deve iniziare esattamente con una delle stringhe specificate.&lt;br&gt;
In questo modo, le righe che iniziano ad es. con "PPid" non vengono selezionate da awk.&lt;br&gt;
Adesso il secondo campo stampato sarà il Pid del processo e il terzo la swap usata.&lt;br&gt;
Il sort lo facciamo quindi sul terzo campo.&lt;/p&gt;

&lt;p&gt;Es. di output del comando:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; /proc/&lt;span class="k"&gt;*&lt;/span&gt;/status &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;&lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'/^(VmSwap:|Name:|Pid:)/ {printf $2 " " $3}END{ print ""}'&lt;/span&gt; &lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-k&lt;/span&gt; 3 &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; | less
gnome-software 6377 218708 kB
mariadbd 46522 155576 kB
code 41703 147548 kB
code 40429 134844 kB
firefox 8840 111212 kB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>linux</category>
      <category>bash</category>
      <category>italian</category>
    </item>
    <item>
      <title>Modificare allarme di spazio libero per un disco in Netdata</title>
      <dc:creator>minnogit</dc:creator>
      <pubDate>Mon, 13 Mar 2023 14:01:40 +0000</pubDate>
      <link>https://dev.to/minnogit/modificare-allarme-di-spazio-libero-per-un-disco-in-netdata-4k54</link>
      <guid>https://dev.to/minnogit/modificare-allarme-di-spazio-libero-per-un-disco-in-netdata-4k54</guid>
      <description>&lt;p&gt;Dall'interfaccia web di Netdata, in alto a destra, si vedono gli allarmi e, nei dettagli di ognuno, sono specificati i relativi file di configurazione.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpbiaog3ghxk1qgfgyz7f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpbiaog3ghxk1qgfgyz7f.png" alt=" " width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ad es., dai dettagli sopra si vede che l'allarme è configurato nel file &lt;em&gt;/opt/netdata/usr/lib/netdata/conf.d/health.d/disks.conf&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Se vogliamo che l'allarme per il disco &lt;em&gt;/mnt/disco_utenti&lt;/em&gt; abbia regole diverse rispetto a quelle per gli altri dischi, possiamo modificare la configurazione così:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano /opt/netdata/usr/lib/netdata/conf.d/health.d/disks.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Escludo il disco &lt;em&gt;/mnt/disco_utenti&lt;/em&gt; dalla configurazione attuale modificando la lista &lt;em&gt;families&lt;/em&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# -----------------------------------------------------------------------------
# low disk space

# checking the latest collected values
# raise an alarm if the disk is low on
# available disk space

 template: disk_space_usage
       on: disk.space
    class: Utilization
     type: System
component: Disk
       os: linux freebsd
    hosts: *
 families: !/mnt/disco_utenti !/mnt/disco_utenti !/dev !/dev/* !/run !/run/* *
     calc: $used * 100 / ($avail + $used)
    units: %
    every: 1m
     warn: $this &amp;gt; (($status &amp;gt;= $WARNING ) ? (80) : (90))
     crit: $this &amp;gt; (($status == $CRITICAL) ? (90) : (98))
    delay: up 1m down 15m multiplier 1.5 max 1h
     info: disk ${label:mount_point} space utilization
       to: sysadmin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Aggiungo alla configurazione una nuova sezione per l'allarme del disco &lt;em&gt;/mnt/disco_utenti&lt;/em&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# -----------------------------------------------------------------------------
# low disk space

# checking the latest collected values
# raise an alarm if the disk is low on
# available disk space

 template: disk_space_usage
       on: disk.space
    class: Utilization
     type: System
component: Disk
       os: linux freebsd
    hosts: *
 families: /mnt/disco_utenti
     calc: $used * 100 / ($avail + $used)
    units: %
    every: 10m
     warn: $this &amp;gt; (($status &amp;gt;= $WARNING ) ? (96) : (98))
     crit: $this &amp;gt; (($status == $CRITICAL) ? (98) : (99))
    delay: up 1m down 15m multiplier 1.5 max 1h
     info: disk ${label:mount_point} space utilization
       to: sysadmin

 template: disk_inode_usage
      on: disk.inodes
    class: Utilization
     type: System
component: Disk
       os: linux freebsd
    hosts: *
 families: !/dev !/dev/* !/run !/run/* *
     calc: $used * 100 / ($avail + $used)
    units: %
    every: 1m
     warn: $this &amp;gt; (($status &amp;gt;= $WARNING)  ? (80) : (90))
     crit: $this &amp;gt; (($status == $CRITICAL) ? (90) : (98))
    delay: up 1m down 15m multiplier 1.5 max 1h
     info: disk ${label:mount_point} inode utilization
       to: sysadmin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Riavviare Netdata:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl restart netdata
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>linux</category>
      <category>monitoring</category>
      <category>italian</category>
      <category>netdata</category>
    </item>
  </channel>
</rss>
