Forum Notenmanager

Normale Version: Backupscripte
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Lieber Stephan,

wir benutzen schon seit Jahr und Tag aus dem Handbuch die angehängten Scripte. Jetzt hat sich ja aber in letzter Zeit viel geändert (wenn auch nicht an der SQL-Datenbank): kannst Du bitte mal drüber schauen ob das so noch passt?

Wieder einspielen eines Vorjahres in eine neue Datenbank geht bei uns jedenfalls immer, aber das ganze Cluster oder die Roles musste ich (Gottseidank) noch nie wiederherstellen...

Oder ist das evtl. gar nicht mehr die empfohlene Backup-Methode und es geht mittlerweile auch direkt aus NM5?


Liebe Grüße,


Gramais




backup_db_cluster.cmd
Code:
SET PGPASSWORD=$redacted
"C:\Programme\PostgreSQL\10\bin\pg_dumpall.exe" --host localhost --port 5432 --username "postgres" --no-password  --verbose --file N:\Backups\Batched_Cluster\dumpall_%date:~6,4%_%date:~3,2%_%date:~0,2%.backup.sql
set PGPASSWORD=null

backup_db.cmd
Code:
@echo off

goto comment

Description: This file use to backup the database using PostgreSQL backup utility "pg_dump".
             Backup parameters should be setup before executing this file

File Format flags :     
                c = Custom
                t = Tar
                p = Plain SQL


    
    Table Excluding Flags:
    -T table_name
    
:comment


REM "Set following backup parameters to take backup"
SET PGPASSWORD=$redacted
SET db_name=redacted
SET file_format=c
SET host_name=localhost
SET user_name=postgres
SET pg_dump_path="C:\Programme\PostgreSQL\10\bin\pg_dump.exe"  
SET target_backup_path=N:\Backups\Batched_DB\
SET other_pg_dump_flags=--blobs --verbose -c

REM Fetch Current System Date and set month,day and year variables
for /f "tokens=1-3 delims=- " %%i in ("%date%") do (
    set month=%%j
    set day=%%i
    set year=%%k
)
for /f "tokens=1-3 delims=: " %%i in ("%time%") do (
    set hour=%%i
    set min=%%j
    set sec=%%k
)


REM Creating string for backup file name
for /f "delims=" %%i in ('dir "%target_backup_path%" /b/a-d ^| find /v /c "::"') do set count=%%i
set /a count=%count%+1
set datestr=backup_%year%_%month%_%day%_%hour%_%min%

REM Backup File name
set BACKUP_FILE=%db_name%_%datestr%.backup

REM :> Executing command to backup database
%pg_dump_path% --host=%host_name% -U %user_name% --format=%file_format%  -f %target_backup_path%%BACKUP_FILE%  %db_name%

REM %pg_dump_path% --host=%host_name% -U %user_name% --format=%file_format%  %other_pg_dump_flags% -f %target_backup_path%%BACKUP_FILE%  %db_name%

ECHO Backup l‰uft ...  Fenster schiesst selbstst‰ndig

backup_db_roles.cmd
Code:
SET PGPASSWORD=$redacted
"C:\Programme\PostgreSQL\10\bin\pg_dumpall.exe" --host localhost --port 5432 --username "postgres" --no-password  --verbose --file N:\Backups\Batched_Roles\pgroles.backup.sql --roles-only
set PGPASSWORD=null
Hallo Gramais,

backup_db_cluster.cmd sollte so noch passen. Brauchst du aber nur, wenn du tatsächlich deinen Postgresql-Server mit allem drum und dran auf eine neue Hardware umziehen willst. Wie im Handbuch geschrieben, kannst du aus einer solchen Sicherung nicht eine einzelne Datenbank wiederherstellen. Ich nutze das Script daher bei uns nicht und sichere alle Datenbanken (NM, ASV) einzeln.

backup_db.cmd stammt ja so nicht von mir, aber nach einem groben drüberschauen scheint das auch so zu passen. Die damit gesicherten Datenbanken hast du ja schon erfolgreich wiederhergestellt, wenn ich dich richtig verstanden habe.

backup_db_roles.cmd ist auch OK. Auch hier werden alle Benutzerkonten gesichert und können nicht einzeln wiederhergestellt werden.

Gruß
Stephan
Tiptop - danke fürs Feedback! smile