https://www.scalingpostgres.com/tutorials/postgresql-backup-point-in-time-recovery/
In this tutorial, we demonstrate how to take a physical backup of a PostgreSQL database cluster and restore it using Point-In-Time Recovery or PITR.
-H -u postgres mkdir /var/lib/postgresql/pg_log_archive
sudo nano /etc/postgresql/10/main/postgresql.conf
wal_level = replica
archive_mode = on archive_command = 'test ! -f /var/lib/postgresql/pg_log_archive/%f && cp %p /var/lib/postgresql/pg_log_archive/%f'
sudo systemctl restart postgresql@10-main
sudo su - postgres
psql -c "create database test;"
psql test -c "
create table posts (
id integer,
title character varying(100),
content text,
published_at timestamp without time zone,
type character varying(100)
);
insert into posts (id, title, content, published_at, type) values
(100, 'Intro to SQL', 'Epic SQL Content', '2018-01-01', 'SQL'),
(101, 'Intro to PostgreSQL', 'PostgreSQL is awesome!', now(), 'PostgreSQL');
"
psql -c "select pg_switch_wal();"
pg_basebackup -Ft -D /var/lib/postgresql/db_file_backup
sudo systemctl stop postgresql@10-main
rm /var/lib/postgresql/10/main/* -r
ls /var/lib/postgresql/10/main/
tar xvf /var/lib/postgresql/db_file_backup/base.tar -C /var/lib/postgresql/10/main/
tar xvf /var/lib/postgresql/db_file_backup/pg_wal.tar -C /var/lib/postgresql/10/main/pg_wal/
nano /var/lib/postgresql/10/main/recovery.conf
restore_command = 'cp /var/lib/postgresql/pg_log_archive/%f %p'
sudo systemctl start postgresql@10-main
psql test -c "select * from posts;"
pg_basebackup -Ft -X none -D - | gzip > /var/lib/postgresql/db_file_backup.tar.gz
psql test -c "insert into posts (id, title, content, type) values
(102, 'Intro to SQL Where Clause', 'Easy as pie!', 'SQL'),
(103, 'Intro to SQL Order Clause', 'What comes first?', 'SQL');"
psql -c "select pg_switch_wal();"
sudo systemctl stop postgresql@10-main
rm /var/lib/postgresql/10/main/* -r
ls /var/lib/postgresql/10/main/
tar xvfz /var/lib/postgresql/db_file_backup.tar.gz -C /var/lib/postgresql/10/main/
nano /var/lib/postgresql/10/main/recovery.conf
restore_command = 'cp /var/lib/postgresql/pg_log_archive/%f %p'
recovery_target_time = '2018-02-22 15:20:00 EST'
sudo systemctl start postgresql@10-main
psql test -c "select * from posts;"
tail -n 100 /var/log/postgresql/postgresql-10-main.log
psql -c "select pg_wal_replay_resume();"
sudo
Tidak ada komentar:
Posting Komentar