SlideShare una empresa de Scribd logo
1 de 83
Descargar para leer sin conexión
PGBACKREST
slardiere PBR – juin 2018 1 / 83
Sébastien Lardière
Utilisateur de PostgreSQL depuis 18 ans
Consultant, formateur, DBA, auteur
Co-animateur du meetup PostgreSQL Nantes
slardiere PBR – juin 2018 2 / 83
Loxodata
Conseil et expertise PostgreSQL
Audit, Formation, Accompagnement
On recrute : recrutement@loxodata.com
https://www.loxodata.com/post/
slardiere PBR – juin 2018 3 / 83
Sauvegarde
Vaste sujet
Vrai sujet : la restauration
Autre besoin : construire un réplica
Maîtriser l’outil et les procédures
slardiere PBR – juin 2018 4 / 83
Mécanismes de la sauvegarde
PostgreSQL les défini :
Archivage des WALs
Sauvegardes des fichiers
pgBackRest les utilise :
implémente ses méthodes
gère son catalogue
industrialise les processus
slardiere PBR – juin 2018 5 / 83
pgBackRest
initié par David Steele et Stephen Frost
important volume à sauvegarder
https://github.com/pgbackrest/pgbackrest
sponsorisé par Crunchy Data
slardiere PBR – juin 2018 6 / 83
pgBackRest : principes
l’unité est le fichier
la sauvegarde est une arborescence
les sauvegardes sont le catalogue
le catalogue est duplicable
slardiere PBR – juin 2018 7 / 83
pgBackRest : Installation
outil écrit en C (et en Perl)
version 2.03 : un seul binaire
utilise ssh
sur tous les nœuds
paquets deb et rpm
slardiere PBR – juin 2018 8 / 83
pgBackRest : Installation
depuis les dépots PGDG :
Exemple
apt install pgbackrest
yum install pgbackrest
slardiere PBR – juin 2018 9 / 83
pgBackRest : Installation
Exemple
/usr/bin/pgbackrest
/etc/pgbackrest/pgbackrest.conf
/etc/pgbackrest/conf.d/*.conf
/var/lib/pgbackrest
/var/log/pgbackrest
/var/spool/pgbackrest
slardiere PBR – juin 2018 10 / 83
pgBackRest : Connexions SSH
commandes et données
clés sans mot de passe
bi-directionnel
slardiere PBR – juin 2018 11 / 83
slardiere PBR – juin 2018 12 / 83
pgBackRest : Configuration
Dépot
Exemple
/etc/pgbackrest/pgbackrest.conf
[global]
repo-path=/var/lib/pgbackrest
slardiere PBR – juin 2018 13 / 83
pgBackRest : Configuration
Stanza : pg01.tolva.net
Exemple
/etc/pgbackrest/conf.d/tolva.conf
[tolva]
pg1-path=/data/postgres/10/main
repo1-host=backrest.tolva.net
repo1-host-user=postgres
slardiere PBR – juin 2018 14 / 83
pgBackRest : Logs
Exemple (config)
/etc/pgbackrest/pgbackrest.conf
[global]
log-level-file=info
slardiere PBR – juin 2018 15 / 83
pgBackRest : Logs
Exemple (commande)
pgbackrest --log-level-console=info
--log-level-stderr=error
slardiere PBR – juin 2018 16 / 83
pgBackRest : Configuration
Stanza : backrest.tolva.net
Exemple
/etc/pgbackrest/conf.d/tolva.conf
[tolva]
pg1-host=pg01.tolva.net
pg1-path=/data/postgres/10/main
pg1-host-user=postgres
slardiere PBR – juin 2018 17 / 83
pgBackRest : Stanza
Création de l’arboresence dans backrest.tolva.net :
Exemple (commande)
pgbackrest --stanza=tolva stanza-create
slardiere PBR – juin 2018 18 / 83
PostgreSQL : Configuration
postgresql.conf
Exemple
wal_level = replica
archive_mode = on
archive_command = ’pgbackrest --stanza=tolva archive-push %p’
slardiere PBR – juin 2018 19 / 83
pgBackRest : Configuration
Stanza : pg01.tolva.net
Exemple (config)
/etc/pgbackrest/conf.d/tolva.conf
[tolva]
...
archive-async=y
archive-push-queue-max=1GB
spool-path=/backup/db/spool
process-max=4
slardiere PBR – juin 2018 20 / 83
pgBackRest : Configuration
Vérification
Exemple (commande)
pgbackrest --log-level-console=info --stanza=tolva check
INFO: WAL segment 000000010000000E00000095 successfully stored in the archive
at ’/var/lib/pgbackrest/archive/tolva/10-1/000000010000000E/
000000010000000E00000095-d69875cb86cd56c52efe0944069eefc10e55d304.gz’
INFO: check command end: completed successfully
slardiere PBR – juin 2018 21 / 83
slardiere PBR – juin 2018 22 / 83
slardiere PBR – juin 2018 23 / 83
Sauvegardes
slardiere PBR – juin 2018 24 / 83
Types
Complète : full
Différentielle : diff
Incrémentale : incr
slardiere PBR – juin 2018 25 / 83
Sauvegardes
Exemple (commande)
pgbackrest --stanza=pg96 --type=incr backup
slardiere PBR – juin 2018 26 / 83
slardiere PBR – juin 2018 27 / 83
slardiere PBR – juin 2018 28 / 83
slardiere PBR – juin 2018 29 / 83
slardiere PBR – juin 2018 30 / 83
slardiere PBR – juin 2018 31 / 83
slardiere PBR – juin 2018 32 / 83
slardiere PBR – juin 2018 33 / 83
slardiere PBR – juin 2018 34 / 83
slardiere PBR – juin 2018 35 / 83
Sauvegardes
Exemple (commande)
pgbackrest --stanza=tolva --type=diff backup
slardiere PBR – juin 2018 36 / 83
slardiere PBR – juin 2018 37 / 83
slardiere PBR – juin 2018 38 / 83
slardiere PBR – juin 2018 39 / 83
slardiere PBR – juin 2018 40 / 83
slardiere PBR – juin 2018 41 / 83
slardiere PBR – juin 2018 42 / 83
slardiere PBR – juin 2018 43 / 83
slardiere PBR – juin 2018 44 / 83
slardiere PBR – juin 2018 45 / 83
Planification
Cron : /etc/cron.d/pgbackrest
Exemple (config)
1 1 1,5 * * postgres pgbackrest --stanza=tolva --type=full
1 1 2,3,4,6,7 * * postgres pgbackrest --stanza=tolva --type=diff
slardiere PBR – juin 2018 46 / 83
slardiere PBR – juin 2018 47 / 83
Configuration
Checkpoint : start-fast
Parallélisation : process-max
Compression : compress-level; compress; compress-level-network
WAL : archive-copy
Somme de contrôle : activé par défaut
slardiere PBR – juin 2018 48 / 83
Configuration
Stanza : backrest.tolva.net
Exemple (config)
/etc/pgbackrest/conf.d/tolva.conf
[tolva]
...
start-fast=y
process-max=4
compress-level=3
archive-copy=y
slardiere PBR – juin 2018 49 / 83
Chiffrement
repo1-cipher-type=aes-256-cbc
repo1-cipher-pass=zWaf6XtpjIVZC5444yXB...
slardiere PBR – juin 2018 50 / 83
S3
repo1-type=s3
repo1-s3-bucket=tolva-pg-backup
repo1-s3-endpoint=s3.amazonaws.com
repo1-s3-region=us-east-1
repo1-s3-key=AKIAIOSFODNN7EXAMPLE
repo1-s3-key-secret=wJalrXUtnFEM...
slardiere PBR – juin 2018 51 / 83
Informations
Exemple (commande)
pgbackrest --stanza=tolva info
diff backup: 20180611-161639F_20180623-160611D
timestamp start/stop: 2018-06-23 16:06:11 / 2018-06-23 16:06:26
wal start/stop: 000000010000000E00000097 / 000000010000000E00000097
database size: 1GB, backup size: 89MB
repository size: 222.7MB, repository backup size: 32.5MB
backup reference list: 20180611-161639F
slardiere PBR – juin 2018 52 / 83
Rétention
full : repo-retention-full
diff : repo-retention-diff
WALs : repo-retention-archive; repo-retention-archive-type
slardiere PBR – juin 2018 53 / 83
slardiere PBR – juin 2018 54 / 83
slardiere PBR – juin 2018 55 / 83
slardiere PBR – juin 2018 56 / 83
slardiere PBR – juin 2018 57 / 83
slardiere PBR – juin 2018 58 / 83
slardiere PBR – juin 2018 59 / 83
slardiere PBR – juin 2018 60 / 83
slardiere PBR – juin 2018 61 / 83
slardiere PBR – juin 2018 62 / 83
slardiere PBR – juin 2018 63 / 83
slardiere PBR – juin 2018 64 / 83
slardiere PBR – juin 2018 65 / 83
Rétention
Stanza : backrest.tolva.net
Exemple (config)
/etc/pgbackrest/conf.d/tolva.conf
[tolva]
...
repo1-retention-full=6
repo1-retention-diff=3
repo1-retention-archive-type=full
repo1-retention-archive=3
slardiere PBR – juin 2018 66 / 83
Restauration
slardiere PBR – juin 2018 67 / 83
Restauration
Préparation de la restauration
Option du PITR
Restauration partielle
Préparation d’un « Standby »
slardiere PBR – juin 2018 68 / 83
Restauration
Par défaut : restore_command
Choix de la sauvegarde : --set
Type de cible : --type
Valeur de la cible : --target
Fin de la restauration : --target-action
Autre option : --recovery-option
slardiere PBR – juin 2018 69 / 83
slardiere PBR – juin 2018 70 / 83
Restauration
Stanza : pg02.tolva.net
Exemple (commande)
pgbackrest --stanza=tolva --set 20180611-161639F_20180623-160611D
--type=name --target=myrestorepoint --target-action=promote restore
slardiere PBR – juin 2018 71 / 83
Restauration
Stanza : pg02.tolva.net
Exemple (commande)
pgbackrest --stanza=tolva --set latest --target-timeline=latest
--recovery-option=primary_conninfo=db.mydomain.com restore
slardiere PBR – juin 2018 72 / 83
Restauration
Fichier : recovery.conf
Exemple (config)
restore_command = ’pgbackrest --stanza=tolva archive-get %f "%p"’
recovery_target_name = ’myrestorepoint’
recovery_target_action = promote
slardiere PBR – juin 2018 73 / 83
slardiere PBR – juin 2018 74 / 83
Restauration
Complément : --delta ( --force )
Base de données à inclure : --db-include
Liens symboliques : --link-all
Modification des liens : --link-map
Relocalisation des tablespaces : --tablespace-map;
--tablespace-map-all
slardiere PBR – juin 2018 75 / 83
Restauration
Stanza : pg02.tolva.net
Exemple (commande)
pgbackrest --stanza=tolva --set latest
--delta --type=preserve restore
slardiere PBR – juin 2018 76 / 83
Restauration
Démarrage normal de PostgreSQL
slardiere PBR – juin 2018 77 / 83
slardiere PBR – juin 2018 78 / 83
pgBackRest : Stanza Upgrade
Montée de version de PostgreSQL :
Exemple (commande)
pgbackrest --stanza=tolva stanza-upgrade
slardiere PBR – juin 2018 79 / 83
pgBackRest : Stanza Stop/Start
Exemple (commande)
pgbackrest --stanza=tolva stop
pgbackrest --stanza=tolva start
slardiere PBR – juin 2018 80 / 83
Use it!
slardiere PBR – juin 2018 81 / 83
Merci!
merci à David Steele!
http://sebastien.lardiere.net/blog/index.php/tag/PostgreSQL
slardiere PBR – juin 2018 82 / 83
Questions?
slardiere PBR – juin 2018 83 / 83

Más contenido relacionado

La actualidad más candente

Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...PostgreSQL-Consulting
 
Using PostgreSQL for Data Privacy
Using PostgreSQL for Data PrivacyUsing PostgreSQL for Data Privacy
Using PostgreSQL for Data PrivacyMason Sharp
 
What is new in PostgreSQL 14?
What is new in PostgreSQL 14?What is new in PostgreSQL 14?
What is new in PostgreSQL 14?Mydbops
 
Pgsodium's Features: those not provided by pgcrypto and integration with rem...
 Pgsodium's Features: those not provided by pgcrypto and integration with rem... Pgsodium's Features: those not provided by pgcrypto and integration with rem...
Pgsodium's Features: those not provided by pgcrypto and integration with rem...EDB
 
Linux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performanceLinux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performancePostgreSQL-Consulting
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재PgDay.Seoul
 
Highly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackupHighly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackupNilnandan Joshi
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenPostgresOpen
 
클라우드 엔지니어 취업 고군 분투기
클라우드 엔지니어 취업 고군 분투기클라우드 엔지니어 취업 고군 분투기
클라우드 엔지니어 취업 고군 분투기InfraEngineer
 
PostgreSQL Materialized Views with Active Record
PostgreSQL Materialized Views with Active RecordPostgreSQL Materialized Views with Active Record
PostgreSQL Materialized Views with Active RecordDavid Roberts
 
Troubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationAlexey Lesovsky
 
Arquitetura de Memoria do PostgreSQL
Arquitetura de Memoria do PostgreSQLArquitetura de Memoria do PostgreSQL
Arquitetura de Memoria do PostgreSQLRaul Oliveira
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep InternalEXEM
 
Hunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows EnvironmentHunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows EnvironmentTeymur Kheirkhabarov
 
How to create a multi tenancy for an interactive data analysis with jupyter h...
How to create a multi tenancy for an interactive data analysis with jupyter h...How to create a multi tenancy for an interactive data analysis with jupyter h...
How to create a multi tenancy for an interactive data analysis with jupyter h...Tiago Simões
 
LISA17 Container Performance Analysis
LISA17 Container Performance AnalysisLISA17 Container Performance Analysis
LISA17 Container Performance AnalysisBrendan Gregg
 
PGAnalytics - Facilitando sua vida do DBA
PGAnalytics - Facilitando sua vida do DBAPGAnalytics - Facilitando sua vida do DBA
PGAnalytics - Facilitando sua vida do DBADextra
 

La actualidad más candente (20)

Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
 
Using PostgreSQL for Data Privacy
Using PostgreSQL for Data PrivacyUsing PostgreSQL for Data Privacy
Using PostgreSQL for Data Privacy
 
What is new in PostgreSQL 14?
What is new in PostgreSQL 14?What is new in PostgreSQL 14?
What is new in PostgreSQL 14?
 
Pgsodium's Features: those not provided by pgcrypto and integration with rem...
 Pgsodium's Features: those not provided by pgcrypto and integration with rem... Pgsodium's Features: those not provided by pgcrypto and integration with rem...
Pgsodium's Features: those not provided by pgcrypto and integration with rem...
 
Linux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performanceLinux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performance
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
 
Zabbix conference 2018v2
Zabbix conference 2018v2Zabbix conference 2018v2
Zabbix conference 2018v2
 
Postgre sql best_practices
Postgre sql best_practicesPostgre sql best_practices
Postgre sql best_practices
 
Highly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackupHighly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackup
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
 
클라우드 엔지니어 취업 고군 분투기
클라우드 엔지니어 취업 고군 분투기클라우드 엔지니어 취업 고군 분투기
클라우드 엔지니어 취업 고군 분투기
 
PostgreSQL Materialized Views with Active Record
PostgreSQL Materialized Views with Active RecordPostgreSQL Materialized Views with Active Record
PostgreSQL Materialized Views with Active Record
 
Troubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming Replication
 
PostgreSQL Replication Tutorial
PostgreSQL Replication TutorialPostgreSQL Replication Tutorial
PostgreSQL Replication Tutorial
 
Arquitetura de Memoria do PostgreSQL
Arquitetura de Memoria do PostgreSQLArquitetura de Memoria do PostgreSQL
Arquitetura de Memoria do PostgreSQL
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 
Hunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows EnvironmentHunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows Environment
 
How to create a multi tenancy for an interactive data analysis with jupyter h...
How to create a multi tenancy for an interactive data analysis with jupyter h...How to create a multi tenancy for an interactive data analysis with jupyter h...
How to create a multi tenancy for an interactive data analysis with jupyter h...
 
LISA17 Container Performance Analysis
LISA17 Container Performance AnalysisLISA17 Container Performance Analysis
LISA17 Container Performance Analysis
 
PGAnalytics - Facilitando sua vida do DBA
PGAnalytics - Facilitando sua vida do DBAPGAnalytics - Facilitando sua vida do DBA
PGAnalytics - Facilitando sua vida do DBA
 

Similar a pgBackRest - pgday.fr

Similar a pgBackRest - pgday.fr (6)

Pgbadger
PgbadgerPgbadger
Pgbadger
 
Pgbackrest meetup
Pgbackrest meetupPgbackrest meetup
Pgbackrest meetup
 
PostgreSQL plprofiler - Mars 2017 - Loxodata
PostgreSQL  plprofiler - Mars 2017 - LoxodataPostgreSQL  plprofiler - Mars 2017 - Loxodata
PostgreSQL plprofiler - Mars 2017 - Loxodata
 
Hibernate.pdf
Hibernate.pdfHibernate.pdf
Hibernate.pdf
 
Django compressor
Django compressorDjango compressor
Django compressor
 
Pg11 pgday 2018
Pg11 pgday 2018Pg11 pgday 2018
Pg11 pgday 2018
 

pgBackRest - pgday.fr