Friday, November 15, 2024

.:: Extract backup mysqldump to convert only table specify (Sample Pembelian) in MySQL MariaDB :::.

 

A. Extract backup from file backup

1. Backup full database

mysqldump -u root -p teguhth  > table_teguhth.sql ;

2. extract table only specific table (example barang)

sed -n -e '/DROP TABLE.*`barang`/,/UNLOCK TABLES/p' table_teguhth.sql > /data/pertable/barang_only.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


mysql -uroot -p pertable < /data/pertable/barang_only.sql

2. check 
 

C. extract all table exclude specific table (example barang)
 
sed '/DROP TABLE.*`barang`/,/UNLOCK TABLES/d' table_teguhth.sql > /data/pertable/without_barang.sql
 
[root@teguhth-all pertable]# sed '/DROP TABLE.*`barang`/,/UNLOCK TABLES/d' table_teguhth.sql > /data/pertable/without_barang.sql
[root@teguhth-all pertable]#
 

 
D. extract all table exclude selected table (example barang, suplier,customer )
 
sed '/DROP TABLE.*`barang`/,/UNLOCK TABLES/d; /DROP TABLE.*`customer`/,/UNLOCK TABLES/d; /DROP TABLE.*`suplier`/,/UNLOCK TABLES/d' table_teguhth.sql > /data/pertable/without_selected_tables.sql
 
[root@teguhth-all pertable]# sed '/DROP TABLE.*`barang`/,/UNLOCK TABLES/d; /DROP TABLE.*`customer`/,/UNLOCK TABLES/d; /DROP TABLE.*`suplier`/,/UNLOCK TABLES/d' table_teguhth.sql > /data/pertable/without_selected_tables.sql
[root@teguhth-all pertable]#
 

 E. extract all table exclude selected table (example barang, suplier,customer ) tapi structure table tetap ikut
  
sed '/LOCK TABLES.*`barang`/,/UNLOCK TABLES/d' table_teguhth.sql > /data/pertable/without_barang_struc.sql

sed '/LOCK TABLE.*`barang`/,/UNLOCK TABLES/d; /LOCK TABLE.*`customer`/,/UNLOCK TABLES/d; /LOCK TABLE.*`suplier`/,/UNLOCK TABLES/d' table_teguhth.sql > /data/pertable/without_selected_tables_struc.sql
 

No comments:

Post a Comment

Popular Posts