$ psql postgres -c "GRANT EXECUTE ON FUNCTION pg_backup_start TO u01" $ psql postgres -c "GRANT EXECUTE ON FUNCTION pg_backup_stop TO u01" $ psql postgres -c "GRANT EXECUTE ON FUNCTION pg_create_restore_point TO u01"
$ ls -al /mnt/workspace/BackupTest/backups/lab/RWSH8U/database/pg_tblspc/16389/PG_15_202209061/5/ total 656708 drwx------ 2 japin japin 4096 Jun 25 11:19 . drwx------ 3 japin japin 4096 Jun 25 11:19 .. -rw------- 1 japin japin 672137600 Jun 25 11:19 16403 -rw------- 1 japin japin 188416 Jun 25 11:19 16403_fsm -rw------- 1 japin japin 24576 Jun 25 11:19 16403_vm -rw------- 1 japin japin 8200 Jun 25 11:19 16404 -rw------- 1 japin japin 24576 Jun 25 11:19 16404_fsm -rw------- 1 japin japin 8192 Jun 25 11:19 16404_vm -rw------- 1 japin japin 24600 Jun 25 11:19 16406 -rw------- 1 japin japin 24576 Jun 25 11:19 16406_fsm -rw------- 1 japin japin 8192 Jun 25 11:19 16406_vm $ ls -al /mnt/workspace/BackupTest/backups/lab/RWSH8U/database/pg_tblspc/16390/PG_15_202209061/5/ total 109876 drwx------ 2 japin japin 4096 Jun 25 11:19 . drwx------ 3 japin japin 4096 Jun 25 11:19 .. -rw------- 1 japin japin 16400 Jun 25 11:19 16407 -rw------- 1 japin japin 32800 Jun 25 11:19 16409 -rw------- 1 japin japin 112446600 Jun 25 11:19 16411
最后,我们来测试恢复过程。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ pg_probackup restore -B /mnt/workspace/BackupTest --instance lab --pgdata $PWD/db-backup INFO: Tablespace 16390 will be restored using old path "/home/japin/lab/idxspc" INFO: Tablespace 16389 will be restored using old path "/home/japin/lab/tblspc" INFO: Validating backup RWSH8U INFO: Backup RWSH8U data files are valid INFO: Backup RWSH8U WAL segments are valid INFO: Backup RWSH8U is valid. INFO: Restoring the database from backup at 2023-06-25 11:19:42+08 INFO: Start restoring backup files. PGDATA size: 802MB INFO: Backup files are restored. Transfered bytes: 802MB, time elapsed: 1s INFO: Restore incremental ratio (less is better): 100% (802MB/802MB) INFO: Syncing restored files to disk INFO: Restored backup files are synced, time elapsed: 3s INFO: Restore of backup RWSH8U completed.
$ pg_ctl stop -l log -D $PWD/db-backup waiting for server to shut down.... done server stopped $ rm -rf db-backup/ idxspc/ tblspc/ $ rm -rf /mnt/workspace/{tblspc,idxspc}/*
$ pg_probackup restore -B /mnt/workspace/BackupTest --instance lab --pgdata $PWD/db-backup \ --tablespace-mapping /home/japin/lab/tblspc=/mnt/workspace/tblspc \ --tablespace-mapping /home/japin/lab/idxspc=/mnt/workspace/idxspc INFO: Tablespace 16390 will be remapped from "/home/japin/lab/idxspc" to "/mnt/workspace/idxspc" INFO: Tablespace 16389 will be remapped from "/home/japin/lab/tblspc" to "/mnt/workspace/tblspc" INFO: Validating backup RWSH8U INFO: Backup RWSH8U data files are valid INFO: Backup RWSH8U WAL segments are valid INFO: Backup RWSH8U is valid. INFO: Restoring the database from backup at 2023-06-25 11:19:42+08 INFO: Start restoring backup files. PGDATA size: 802MB INFO: Backup files are restored. Transfered bytes: 802MB, time elapsed: 2s INFO: Restore incremental ratio (less is better): 100% (802MB/802MB) INFO: Syncing restored files to disk INFO: Restored backup files are synced, time elapsed: 1s INFO: Restore of backup RWSH8U completed.