Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
postgresql_backup_recovery_physical [2019/09/16 07:06] – andonovj | postgresql_backup_recovery_physical [2020/01/27 17:45] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 10: | Line 10: | ||
Base backup in PostgreSQL can be done using two different methods: | Base backup in PostgreSQL can be done using two different methods: | ||
- | + | **Old** | |
- | First one is using the standard Linux commands: scp, cp, rsync, etc: | + | |
- Ensure that WAL archiving is enabled and working. | - Ensure that WAL archiving is enabled and working. | ||
Line 19: | Line 18: | ||
- SELECT pg_stop_backup(); | - SELECT pg_stop_backup(); | ||
- | Second | + | **Newer** |
Let's start with the first one: | Let's start with the first one: | ||
Line 117: | Line 116: | ||
- | =====Restore & Recovery===== | + | ===== Restore & Recovery ===== |
Restore and Recovery have been ALWAYS a different topics in the eyes of a DBA: | Restore and Recovery have been ALWAYS a different topics in the eyes of a DBA: | ||
Line 123: | Line 122: | ||
* Recovery - Relates to the synchronization between the datafiles and log files, in other words making everything consistent. | * Recovery - Relates to the synchronization between the datafiles and log files, in other words making everything consistent. | ||
- | ====Whole Server==== | + | ====Restore==== |
+ | Restore of pg_basebackup is done by copying the content of the backup in the data folder. That's all. Pg_basebackup performs consistent backup and as such it is enough just to copy the content on empty data dir. Please be sure to keep the OLD WAL files prior any deletion. They are extremely important. | ||
+ | |||
+ | <sxh bash> | ||
+ | -bash-4.2$ rm -rf / | ||
+ | -bash-4.2$ mkdir / | ||
+ | -bash-4.2$ chmod 700 / | ||
+ | -bash-4.2$ cp -R * / | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====Recovery==== | ||
+ | Manual recovery is done by creating recovery.conf file, for example: | ||
+ | <sxh bash> | ||
+ | restore_command = 'cp barman_xlog/ | ||
+ | recovery_end_command = 'rm -fr barman_xlog' | ||
+ | recovery_target_time = ' | ||
+ | </ | ||
+ | |||
+ | And restart the service: | ||
+ | |||
+ | <sxh bash> | ||
+ | -bash-4.2$ / | ||
+ | waiting for server to start....2020-01-22 09: | ||
+ | 2020-01-22 09: | ||
+ | 2020-01-22 09: | ||
+ | 2020-01-22 09: | ||
+ | 2020-01-22 09: | ||
+ | 2020-01-22 09: | ||
+ | </ | ||
+ | |||
+ | Alternatively, | ||
+ | |||
+ | ====Using Barman==== | ||
With Barman we can easily restore your server, if you have one :). Please ensure that **YOU NEVER RESTORE IN YOUR ORIGINAL DATA DIRECTORY**, | With Barman we can easily restore your server, if you have one :). Please ensure that **YOU NEVER RESTORE IN YOUR ORIGINAL DATA DIRECTORY**, | ||