pgBackRest Full Back up Restore
pgBackRest ile full backup’dan nasıl geri çevilir aktarılacaktır.
Backup listemizi aşağıdaki gibi görebilirsiniz.
-bash-4.2$ pgbackrest --stanza=12_main info
WARN: configuration file contains invalid option 'repo1-retention-incr'
stanza: 12_main
status: ok
cipher: none
db (current)
wal archive min/max (12-1): 00000001000000000000001B/000000020000000000000023
full backup: 20191209-174948F
timestamp start/stop: 2019-12-09 17:49:48 / 2019-12-09 17:50:09
wal start/stop: 00000001000000000000001B / 00000001000000000000001B
database size: 162.8MB, backup size: 162.8MB
repository size: 8MB, repository backup size: 8MB
incr backup: 20191209-174948F_20191209-200905I
timestamp start/stop: 2019-12-09 20:09:05 / 2019-12-09 20:09:10
wal start/stop: 00000001000000000000001F / 00000001000000000000001F
database size: 162.9MB, backup size: 264.5KB
repository size: 8MB, repository backup size: 11.7KB
backup reference list: 20191209-174948F
diff backup: 20191209-174948F_20191209-200926D
timestamp start/stop: 2019-12-09 20:09:26 / 2019-12-09 20:09:30
wal start/stop: 000000010000000000000021 / 000000010000000000000021
database size: 162.9MB, backup size: 264.7KB
repository size: 8MB, repository backup size: 11.7KB
backup reference list: 20191209-174948F
Veri tabanımızı aşağıdaki komut ile kapatalım.
systemctl stop postgresql-12.service
Aşağıdaki komut ile veri tabanınızdaki bir dosyanızı silerek veri tabanını açılmayacak duruma getirin.
rm -rf /var/lib/pgsql/12/data/global/pg_control
Veri tabanımızı aşağıdaki komut ile açmaya çalışalım.
systemctl start postgresql-12.service
Aşağıdaki hatayı aldığınızı göreceksiniz.
Job for postgresql-12.service failed because the control process exited with error code. See "systemctl status postgresql-12.service" and "journalctl -xe" for details
Hataya aşağıdaki komut ile baktığınızda; silmiş olduğunuz dosyadan dolayı veri tabanınızın açılmadığını göreceksiniz.
[root@postgres eng]# journalctl -xe
-- Unit postgresql-12.service has begun shutting down.
Dec 10 09:59:34 postgres systemd[1]: Stopped PostgreSQL 12 database server.
-- Subject: Unit postgresql-12.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Unit postgresql-12.service has finished shutting down.
Dec 10 09:59:34 postgres polkitd[5638]: Unregistered Authentication Agent for unix-process:39051:2745754 (system bus name :1.1372, object pa
Dec 10 09:59:37 postgres nautilus-deskto[7469]: g_simple_action_set_enabled: assertion 'G_IS_SIMPLE_ACTION (simple)' failed
Dec 10 09:59:44 postgres nautilus-deskto[7469]: g_simple_action_set_enabled: assertion 'G_IS_SIMPLE_ACTION (simple)' failed
Dec 10 09:59:45 postgres polkitd[5638]: Registered Authentication Agent for unix-process:39092:2746949 (system bus name :1.1373 [/usr/bin/pk
Dec 10 09:59:45 postgres systemd[1]: Starting PostgreSQL 12 database server...
-- Subject: Unit postgresql-12.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Unit postgresql-12.service has begun starting up.
Dec 10 09:59:45 postgres postmaster[39107]: postmaster: could not find the database system
Dec 10 09:59:45 postgres postmaster[39107]: Expected to find it in the directory "/var/lib/pgsql/12/data",
Dec 10 09:59:45 postgres postmaster[39107]: but could not open file "/var/lib/pgsql/12/data/global/pg_control": No such file or directory
Dec 10 09:59:45 postgres systemd[1]: postgresql-12.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Dec 10 09:59:45 postgres systemd[1]: Failed to start PostgreSQL 12 database server.
-- Subject: Unit postgresql-12.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Unit postgresql-12.service has failed.
-- The result is failed.
Dec 10 09:59:45 postgres systemd[1]: Unit postgresql-12.service entered failed state.
Dec 10 09:59:45 postgres systemd[1]: postgresql-12.service failed.
Dec 10 09:59:45 postgres polkitd[5638]: Unregistered Authentication Agent for unix-process:39092:2746949 (system bus name :1.1373, object pa
Dec 10 09:59:51 postgres nautilus-deskto[7469]: g_simple_action_set_enabled: assertion 'G_IS_SIMPLE_ACTION (simple)' failed
Veri tabanı crash olmuş durumdadır; bu yüzden data dizinini bulup aşağıdaki komut ile silmeniz gerekmektedir.
[root@postgres eng]# sudo -u postgres find /var/lib/pgsql/12/data -mindepth 1 -delete
Aşağıdaki komut ile son alınan full backup'a dönülür.
sudo -u postgres pgbackrest --stanza=12_main restore
Sonrasında aşağıdaki komut ile veri tabanı açılır.
[root@postgres eng]# systemctl start postgresql-12.service
Ve aşağıdaki işlemlerle veri tabanımızı kontrol ederiz.
[root@postgres eng]# su - postgres
Last login: Tue Dec 10 09:58:25 +03 2019 on pts/0
-bash-4.2$ psql
psql (12.1)
Type "help" for help.
postgres=# c eng
You are now connected to database "eng" as user "postgres".
eng=# dt
List of relations
Schema | Name | Type | Owner
--------+-------+-------+----------
public | den | table | postgres
public | osman | table | postgres
Yazar: Engin YILMAZ