A. Extract backup from file backup
1. Backup full database
pg_dump teguhth > teguhth_singledb.sql
2. extract table only specific table (example barang)
---yang benar
sed -n '/-- Name: barang; Type: TABLE; Schema: public; Owner: postgres/,/ALTER TABLE public.barang OWNER TO postgres;/p' teguhth_singledb.sql > barang_filtered.sql
sed -n '/-- Name: barang barang_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres/,/);/p' teguhth_singledb.sql >> barang_filtered.sql
sed -n '/-- Data for Name: barang; Type: TABLE DATA; Schema: public; Owner: postgres/,/\\\./p' teguhth_singledb.sql >> barang_filtered.sql
--yang benar
sed -n '/-- Name: pembelian; Type: TABLE; Schema: public; Owner: postgres/,/ALTER TABLE public.pembelian OWNER TO postgres;/p' teguhth_singledb.sql > pembelian_filtered.sql
sed -n '/-- Name: pembelian pembelian_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres/,/);/p' teguhth_singledb.sql >> pembelian_filtered.sql
sed -n '/-- Data for Name: pembelian; Type: TABLE DATA; Schema: public; Owner: postgres/,/\\\./p' teguhth_singledb.sql >> pembelian_filtered.sql
3. check result
4. now you have backup full only one table from extract and ready to restore
B. Restore backup from extract
1. Restore
psql pertable < barang_filtered.sql
2. check
No comments:
Post a Comment