{"id":500,"date":"2022-06-15T16:49:58","date_gmt":"2022-06-15T15:49:58","guid":{"rendered":"https:\/\/blog.sguazz.it\/?p=500"},"modified":"2022-06-16T11:36:09","modified_gmt":"2022-06-16T10:36:09","slug":"opzioni-di-barman-per-il-ripristino-di-un-database-postgresql","status":"publish","type":"post","link":"https:\/\/blog.sguazz.it\/index.php\/archives\/500","title":{"rendered":"Opzioni di barman per il ripristino di un database PostgreSQL"},"content":{"rendered":"\n<p>La documentazione di barman non \u00e8 sempre semplice da consultare, quindi aggioungo qui alcune note relative al comando di ripristino.<\/p>\n\n\n\n<p>Creazione del file system per il ripristino, su macchina <em>nomehost<\/em>, aggiornato con tutti i WAL: <code>barman recover --remote-ssh-command 'ssh postgres@<em>nomehost<\/em>' <em>nome-master<\/em> <em>backup-id<\/em> \/path\/destinazione\/su\/nomehost<\/code><\/p>\n\n\n\n<p>Creazione del file system per il ripristino, su macchina <em>nomehost<\/em>, che verr\u00e0 aggiornato con tutti i WAL scaricati all&#8217;avvio di postgres. Il comando per scaricare i WAL dal server barman \u00e8 nel file <strong>recovery.conf<\/strong>: <code>barman recover --remote-ssh-command 'ssh postgres@<em>nomehost<\/em>' <strong>--get-wal<\/strong> <em>nome-master<\/em> <em>backup-id<\/em> \/path\/destinazione\/su\/nomehost<\/code><\/p>\n\n\n\n<p>Creazione del file system per il ripristino, su macchina <em>nomehost<\/em>, che verr\u00e0 configurato come standby (che rimarr\u00e0 sempre in recovery, attendendo sempre nuovi WAL). Il comando per la configurazione \u00e8 nel file <strong>recovery.conf<\/strong>: <code>barman recover --remote-ssh-command 'ssh postgres@<em>nomehost<\/em>' <strong>--standby-mode<\/strong> <em>nome-master<\/em> <em>backup-id<\/em> \/path\/destinazione\/su\/nomehost<\/code><\/p>\n\n\n\n<p>Creazione del file system per il ripristino, su macchina <em>nomehost<\/em>, che verr\u00e0 configurato come standby <strong>e messo in attesa<\/strong> per potervvi accedere. Il comando per la configurazione \u00e8 nel file configurato come standby. Il comando per la configurazione \u00e8 nel file <strong>recovery.conf<\/strong>: <code>barman recover --remote-ssh-command 'ssh postgres@<em>nomehost<\/em>' <strong>--standby-mode<\/strong> <strong>--target-action pause<\/strong> <em>nome-master<\/em> <em>backup-id<\/em> \/path\/destinazione\/su\/nomehost<\/code><\/p>\n\n\n\n<p>Creazione del file system per il ripristino, su macchina <em>nomehost<\/em>, aggiornato con tutti i WAL fino a data e orario specifico. La directory <strong>barman_wal<\/strong> conterr\u00e0 i WAL necessari, il file <strong>recovery.conf<\/strong> i comandi necessari per il PITR: <code>barman recover --remote-ssh-command 'ssh postgres@<em>nomehost<\/em>' <strong>--target-time '2022-06-15 16:58'<\/strong> <em>nome-master<\/em> <em>backup-id<\/em> \/path\/destinazione\/su\/nomehost<\/code><\/p>\n\n\n\n<p>Per fare poi ripartire il database in modalit\u00e0 standby, nel caso che la versione di postgresql sia 12 o superiore, <strong>il file <code>recovery.conf<\/code> non viene usato<\/strong> e, anzi, blocca l&#8217;avvio di postgresql. I comandi vanni presi da quel file e integrati nel file postgresql.conf principale (dettagli <a href=\"https:\/\/www.postgresql.org\/docs\/12\/recovery-config.html\">qui<\/a>).<\/p>\n\n\n\n<p>Altra cosa importante: per fare ripartire postgresql (12 o superiore) in modalit\u00e0 recovery deve esistere il file chiamato <code>standby.signal<\/code>. In caso negativo, il cluster non partir\u00e0 in maniera recovery, ma si aprir\u00e0 normalmente alle connessioni in lettura e scrittura.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>La documentazione di barman non \u00e8 sempre semplice da consultare, quindi aggioungo qui alcune note relative al comando di ripristino. Creazione del file system per il ripristino, su macchina nomehost, aggiornato con tutti i WAL: barman recover &#8211;remote-ssh-command &#8216;ssh postgres@nomehost&#8217; nome-master backup-id \/path\/destinazione\/su\/nomehost Creazione del file system per il ripristino, su macchina nomehost, che verr\u00e0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3,11,10],"tags":[],"class_list":["post-500","post","type-post","status-publish","format-standard","hentry","category-sysadmin","category-computer","category-debian","category-open-source"],"_links":{"self":[{"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/posts\/500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/comments?post=500"}],"version-history":[{"count":3,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/posts\/500\/revisions"}],"predecessor-version":[{"id":503,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/posts\/500\/revisions\/503"}],"wp:attachment":[{"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/media?parent=500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/categories?post=500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/tags?post=500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}