{"id":1586,"date":"2016-04-25T15:36:34","date_gmt":"2016-04-25T14:36:34","guid":{"rendered":"http:\/\/doc.atlantisevo.com\/?post_type=manual_documentation&#038;p=1586"},"modified":"2021-01-27T21:05:31","modified_gmt":"2021-01-27T20:05:31","slug":"schedulare-backup-in-postgresql","status":"publish","type":"manual_documentation","link":"https:\/\/www.atlantisevo.com\/doc\/manuale\/come-fare\/postgres\/schedulare-backup-in-postgresql\/","title":{"rendered":"Schedulare Backup in PostgreSQL"},"content":{"rendered":"<div id=\"toctoc\"><\/div><p>Per poter schedulare un<strong> backup su PostgreSQL<\/strong> 9.x \u00e8 necessario predisporre un file batch da schedulare tramite l&#8217;<span class=\"phrase\"><span class=\"ui\">Utilit\u00e0 di pianificazione di Windows.<\/span><\/span><\/p>\n<p>Il contenuto del batch dovr\u00e0 contenere il comando di PostgreSQL incaricare ad eseguire il dump con gli opportuni parametri. La sintassi \u00e8 la seguente:<\/p>\n<p>pg_dump.exe -O &#8211;dbname=postgresql:\/\/<strong><em>utente<\/em><\/strong>:<strong><em>password<\/em><\/strong>@<strong><em>host<\/em><\/strong>:<strong><em>porta<\/em><\/strong>\/<strong><em>nome_db <\/em><\/strong>-f <strong><em>nome_file.sql<\/em><\/strong><\/p>\n<p>Sostituire i paramentri in grassetto\/italico con gli opportuni valori.<\/p>\n<p>Es.:<\/p>\n<p><code>pg_dump.exe -O --dbname=postgresql:\/\/sa:sa@127.0.0.1:5432\/daodb -f backup.sql<\/code><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>Come alternativa \u00e8 possibile creare un file batch come il seguente, che permette di mantenere un backup mensile:<\/p>\n<p><code>@echo off<\/code><br \/>\n<code> for \/f \"tokens=1-4 delims=\/ \" %%i in (\"%date%\") do (<\/code><br \/>\n<code> set day=%%i<\/code><br \/>\n<code> set month=%%j<\/code><br \/>\n<code> set year=%%k <\/code><br \/>\n<code> )<\/code><br \/>\n<code> set datestr=%day%<\/code><br \/>\n<code> echo datestr is %datestr%<\/code><br \/>\n<code> set BACKUP_FILE=atlantis_%datestr%.backup<\/code><br \/>\n<code> echo backup file name is %BACKUP_FILE%<\/code><br \/>\n<code> SET PGPASSWORD=<strong>&lt;PASSWORD&gt;<\/strong><\/code><br \/>\n<code> echo on<\/code><br \/>\n<code> \"c:\\Program Files\\PostgreSQL\\9.3\\bin\\pg_dump.exe\" -i -h <strong>&lt;HOST&gt;<\/strong>\u00a0-p 5432 -O -U <strong>&lt;UTENTE&gt;<\/strong>\u00a0-F c -b -v -f %BACKUP_FILE%\u00a0<strong>&lt;NOME_DB&gt;<\/strong><\/code><\/p>\n<p>Schedulando un backup giornaliero \u00e8 possibile ottenere la storia dei backup di un mese intero. Il batch in questione crea un backup denominato atlantis_&lt;giorno&gt;.backup<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1583,"menu_order":20,"template":"","manualdocumentationcategory":[55],"manual_doc_tag":[],"_links":{"self":[{"href":"https:\/\/www.atlantisevo.com\/doc\/wp-json\/wp\/v2\/manual_documentation\/1586"}],"collection":[{"href":"https:\/\/www.atlantisevo.com\/doc\/wp-json\/wp\/v2\/manual_documentation"}],"about":[{"href":"https:\/\/www.atlantisevo.com\/doc\/wp-json\/wp\/v2\/types\/manual_documentation"}],"author":[{"embeddable":true,"href":"https:\/\/www.atlantisevo.com\/doc\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":7,"href":"https:\/\/www.atlantisevo.com\/doc\/wp-json\/wp\/v2\/manual_documentation\/1586\/revisions"}],"predecessor-version":[{"id":4644,"href":"https:\/\/www.atlantisevo.com\/doc\/wp-json\/wp\/v2\/manual_documentation\/1586\/revisions\/4644"}],"up":[{"embeddable":true,"href":"https:\/\/www.atlantisevo.com\/doc\/wp-json\/wp\/v2\/manual_documentation\/1583"}],"wp:attachment":[{"href":"https:\/\/www.atlantisevo.com\/doc\/wp-json\/wp\/v2\/media?parent=1586"}],"wp:term":[{"taxonomy":"manualdocumentationcategory","embeddable":true,"href":"https:\/\/www.atlantisevo.com\/doc\/wp-json\/wp\/v2\/manualdocumentationcategory?post=1586"},{"taxonomy":"manual_doc_tag","embeddable":true,"href":"https:\/\/www.atlantisevo.com\/doc\/wp-json\/wp\/v2\/manual_doc_tag?post=1586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}