From ca00b087bbc9e21ad89cd4d87a79c542ebdf1e45 Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Fri, 1 Dec 2023 01:42:30 +0530 Subject: [PATCH] Add bak-restoration script --- .../bak-restoration.sql | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 backup-restoration-scripts/bak-restoration.sql diff --git a/backup-restoration-scripts/bak-restoration.sql b/backup-restoration-scripts/bak-restoration.sql new file mode 100644 index 0000000..5669068 --- /dev/null +++ b/backup-restoration-scripts/bak-restoration.sql @@ -0,0 +1,43 @@ +/* +=====Before runnning the script===== +Data File (.mdf): Contains the actual data and database objects. +Log File (.ldf): Records transactions and modifications for recovery purposes. +Backup File (.bak): A backup file containing a copy of the data and log files. + +1. Specify correct .bak file path +2. Specify the new locations for .mdf, .ldf files using the WITH MOVE clause. +*/ + +/* +In case of below error --> +"Cannot open backup device '/home/kavin/dbdump/'. Operating system error 5(Access is denied.)." + +Grant permissions to directory : chmod o+w /home/kavin/dbdump/ +*/ + +/* +In case of below error --> +"The sp_configure value 'contained database authentication' must be set to 1 in order to restore a contained database. +You may need to use RECONFIGURE to set the value_in_use." + +comment out section: Enable contained database authentication and re-run the script again +*/ + + +/* +-- Enable contained database authentication +sp_configure 'contained database authentication', 1; +GO +RECONFIGURE; +GO +*/ + +-- Restore the database with the MOVE clause +RESTORE DATABASE bst_mdmum_reg +FROM DISK = '/home/kavin/bst_mdmum_reg_Full_20231129193000.BAK' +WITH + MOVE 'bst_mdmum_reg' TO '/home/kavin/dbdump/bst_mdmum_reg.mdf', + MOVE 'bst_mdmum_reg_log' TO '/home/kavin/dbdump/bst_mdmum_reg_log.ldf', + NOUNLOAD, + STATS = 5; +GO