How to make a distibutable .bak file?










1















I am trying to restore 2 databases. One is adventureworks database downloaded from msdn(its .bak file), and another one is created by me from one databases from my old server. Both have .bak extension, are in the same folder where the new instance where they should be restored, has all the access privileges. Now while restoring adventureworks database everything goes alright. While trying to restore the other .bak file made by me I get an access error, it wants access to its original server's DATA folder. Here is the error
enter image description here
Now, I want to know how to create .bak backup in order to restore it to any other server without this error.



Thanks for your time!










share|improve this question




























    1















    I am trying to restore 2 databases. One is adventureworks database downloaded from msdn(its .bak file), and another one is created by me from one databases from my old server. Both have .bak extension, are in the same folder where the new instance where they should be restored, has all the access privileges. Now while restoring adventureworks database everything goes alright. While trying to restore the other .bak file made by me I get an access error, it wants access to its original server's DATA folder. Here is the error
    enter image description here
    Now, I want to know how to create .bak backup in order to restore it to any other server without this error.



    Thanks for your time!










    share|improve this question


























      1












      1








      1








      I am trying to restore 2 databases. One is adventureworks database downloaded from msdn(its .bak file), and another one is created by me from one databases from my old server. Both have .bak extension, are in the same folder where the new instance where they should be restored, has all the access privileges. Now while restoring adventureworks database everything goes alright. While trying to restore the other .bak file made by me I get an access error, it wants access to its original server's DATA folder. Here is the error
      enter image description here
      Now, I want to know how to create .bak backup in order to restore it to any other server without this error.



      Thanks for your time!










      share|improve this question
















      I am trying to restore 2 databases. One is adventureworks database downloaded from msdn(its .bak file), and another one is created by me from one databases from my old server. Both have .bak extension, are in the same folder where the new instance where they should be restored, has all the access privileges. Now while restoring adventureworks database everything goes alright. While trying to restore the other .bak file made by me I get an access error, it wants access to its original server's DATA folder. Here is the error
      enter image description here
      Now, I want to know how to create .bak backup in order to restore it to any other server without this error.



      Thanks for your time!







      sql-server backup restore






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 '18 at 15:00









      Goncalo Peres

      133114




      133114










      asked Nov 10 '18 at 14:23









      Eleonora GrigoryanEleonora Grigoryan

      58114




      58114




















          1 Answer
          1






          active

          oldest

          votes


















          2














          SQL Server won't automatically restore a database to the folder where the .BAK is located. This would be a disaster waiting to happen (say, that drive is out of space, or is encrypted or compressed, or SQL Server only has read access). Instead, it will try to place the files using the same configuration they had on the system they were backed up from. As Tibor alluded to in a comment below, you certainly could standardize all of your users' installs to have SQL Server installed to the same data folders as the source system, or at least all have the same data folder available to write to.



          Barring that, you need to use RESTORE ... WITH MOVE in order to place the data and log files in the right folder for this instance. First verify what that is:



          EXEC master.sys.sp_helpfile;


          That will give you two rows with paths like:



          filename
          ------------------------
          C:somepathmaster.mdf
          C:somepathmastlog.ldf


          Now run the following from the backup file:



          RESTORE FILELISTONLY FROM DISK = 'C:pathfile.bak';


          This will give you a row for each file in the backup, corresponding to each data/log file you'll need to restore (and move). For example:



          LogicalName
          -----------
          AdventureWorks2016_Data
          AdventureWorks2017_Log


          Take the C:somepath part from the first query, and the logical names from the second query, into a statement like this:



          RESTORE DATABASE AdventureWorks
          FROM DISK = 'C:pathfile.bak'
          WITH REPLACE, RECOVERY,
          MOVE 'AdventureWorks2016_Data' TO 'C:somepathaw.mdf',
          MOVE 'AdventureWorks2016_Log' TO 'C:somepathaw.ldf';


          There are likely complications when your backup includes things like filestream or In-Memory OLTP.



          But if your goal is to make a "distributable" backup that will do all that work for the end user, I don't think a traditional SQL Server backup is what you are looking for. Maybe you should look into database projects or providing scripts instead of backups.






          share|improve this answer

























          • Just to emphasize that where the database files are to be created will default to where they were when the backup was produced. So unless you can enforce a folder (the same for all your users) for where to put the database files, your users need to use the MOVE option in the RESTORE command. There's no option in the backup to say "put it in the destinations servers default database files folder".

            – Tibor Karaszi
            Nov 10 '18 at 18:37










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "182"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f222254%2fhow-to-make-a-distibutable-bak-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          SQL Server won't automatically restore a database to the folder where the .BAK is located. This would be a disaster waiting to happen (say, that drive is out of space, or is encrypted or compressed, or SQL Server only has read access). Instead, it will try to place the files using the same configuration they had on the system they were backed up from. As Tibor alluded to in a comment below, you certainly could standardize all of your users' installs to have SQL Server installed to the same data folders as the source system, or at least all have the same data folder available to write to.



          Barring that, you need to use RESTORE ... WITH MOVE in order to place the data and log files in the right folder for this instance. First verify what that is:



          EXEC master.sys.sp_helpfile;


          That will give you two rows with paths like:



          filename
          ------------------------
          C:somepathmaster.mdf
          C:somepathmastlog.ldf


          Now run the following from the backup file:



          RESTORE FILELISTONLY FROM DISK = 'C:pathfile.bak';


          This will give you a row for each file in the backup, corresponding to each data/log file you'll need to restore (and move). For example:



          LogicalName
          -----------
          AdventureWorks2016_Data
          AdventureWorks2017_Log


          Take the C:somepath part from the first query, and the logical names from the second query, into a statement like this:



          RESTORE DATABASE AdventureWorks
          FROM DISK = 'C:pathfile.bak'
          WITH REPLACE, RECOVERY,
          MOVE 'AdventureWorks2016_Data' TO 'C:somepathaw.mdf',
          MOVE 'AdventureWorks2016_Log' TO 'C:somepathaw.ldf';


          There are likely complications when your backup includes things like filestream or In-Memory OLTP.



          But if your goal is to make a "distributable" backup that will do all that work for the end user, I don't think a traditional SQL Server backup is what you are looking for. Maybe you should look into database projects or providing scripts instead of backups.






          share|improve this answer

























          • Just to emphasize that where the database files are to be created will default to where they were when the backup was produced. So unless you can enforce a folder (the same for all your users) for where to put the database files, your users need to use the MOVE option in the RESTORE command. There's no option in the backup to say "put it in the destinations servers default database files folder".

            – Tibor Karaszi
            Nov 10 '18 at 18:37















          2














          SQL Server won't automatically restore a database to the folder where the .BAK is located. This would be a disaster waiting to happen (say, that drive is out of space, or is encrypted or compressed, or SQL Server only has read access). Instead, it will try to place the files using the same configuration they had on the system they were backed up from. As Tibor alluded to in a comment below, you certainly could standardize all of your users' installs to have SQL Server installed to the same data folders as the source system, or at least all have the same data folder available to write to.



          Barring that, you need to use RESTORE ... WITH MOVE in order to place the data and log files in the right folder for this instance. First verify what that is:



          EXEC master.sys.sp_helpfile;


          That will give you two rows with paths like:



          filename
          ------------------------
          C:somepathmaster.mdf
          C:somepathmastlog.ldf


          Now run the following from the backup file:



          RESTORE FILELISTONLY FROM DISK = 'C:pathfile.bak';


          This will give you a row for each file in the backup, corresponding to each data/log file you'll need to restore (and move). For example:



          LogicalName
          -----------
          AdventureWorks2016_Data
          AdventureWorks2017_Log


          Take the C:somepath part from the first query, and the logical names from the second query, into a statement like this:



          RESTORE DATABASE AdventureWorks
          FROM DISK = 'C:pathfile.bak'
          WITH REPLACE, RECOVERY,
          MOVE 'AdventureWorks2016_Data' TO 'C:somepathaw.mdf',
          MOVE 'AdventureWorks2016_Log' TO 'C:somepathaw.ldf';


          There are likely complications when your backup includes things like filestream or In-Memory OLTP.



          But if your goal is to make a "distributable" backup that will do all that work for the end user, I don't think a traditional SQL Server backup is what you are looking for. Maybe you should look into database projects or providing scripts instead of backups.






          share|improve this answer

























          • Just to emphasize that where the database files are to be created will default to where they were when the backup was produced. So unless you can enforce a folder (the same for all your users) for where to put the database files, your users need to use the MOVE option in the RESTORE command. There's no option in the backup to say "put it in the destinations servers default database files folder".

            – Tibor Karaszi
            Nov 10 '18 at 18:37













          2












          2








          2







          SQL Server won't automatically restore a database to the folder where the .BAK is located. This would be a disaster waiting to happen (say, that drive is out of space, or is encrypted or compressed, or SQL Server only has read access). Instead, it will try to place the files using the same configuration they had on the system they were backed up from. As Tibor alluded to in a comment below, you certainly could standardize all of your users' installs to have SQL Server installed to the same data folders as the source system, or at least all have the same data folder available to write to.



          Barring that, you need to use RESTORE ... WITH MOVE in order to place the data and log files in the right folder for this instance. First verify what that is:



          EXEC master.sys.sp_helpfile;


          That will give you two rows with paths like:



          filename
          ------------------------
          C:somepathmaster.mdf
          C:somepathmastlog.ldf


          Now run the following from the backup file:



          RESTORE FILELISTONLY FROM DISK = 'C:pathfile.bak';


          This will give you a row for each file in the backup, corresponding to each data/log file you'll need to restore (and move). For example:



          LogicalName
          -----------
          AdventureWorks2016_Data
          AdventureWorks2017_Log


          Take the C:somepath part from the first query, and the logical names from the second query, into a statement like this:



          RESTORE DATABASE AdventureWorks
          FROM DISK = 'C:pathfile.bak'
          WITH REPLACE, RECOVERY,
          MOVE 'AdventureWorks2016_Data' TO 'C:somepathaw.mdf',
          MOVE 'AdventureWorks2016_Log' TO 'C:somepathaw.ldf';


          There are likely complications when your backup includes things like filestream or In-Memory OLTP.



          But if your goal is to make a "distributable" backup that will do all that work for the end user, I don't think a traditional SQL Server backup is what you are looking for. Maybe you should look into database projects or providing scripts instead of backups.






          share|improve this answer















          SQL Server won't automatically restore a database to the folder where the .BAK is located. This would be a disaster waiting to happen (say, that drive is out of space, or is encrypted or compressed, or SQL Server only has read access). Instead, it will try to place the files using the same configuration they had on the system they were backed up from. As Tibor alluded to in a comment below, you certainly could standardize all of your users' installs to have SQL Server installed to the same data folders as the source system, or at least all have the same data folder available to write to.



          Barring that, you need to use RESTORE ... WITH MOVE in order to place the data and log files in the right folder for this instance. First verify what that is:



          EXEC master.sys.sp_helpfile;


          That will give you two rows with paths like:



          filename
          ------------------------
          C:somepathmaster.mdf
          C:somepathmastlog.ldf


          Now run the following from the backup file:



          RESTORE FILELISTONLY FROM DISK = 'C:pathfile.bak';


          This will give you a row for each file in the backup, corresponding to each data/log file you'll need to restore (and move). For example:



          LogicalName
          -----------
          AdventureWorks2016_Data
          AdventureWorks2017_Log


          Take the C:somepath part from the first query, and the logical names from the second query, into a statement like this:



          RESTORE DATABASE AdventureWorks
          FROM DISK = 'C:pathfile.bak'
          WITH REPLACE, RECOVERY,
          MOVE 'AdventureWorks2016_Data' TO 'C:somepathaw.mdf',
          MOVE 'AdventureWorks2016_Log' TO 'C:somepathaw.ldf';


          There are likely complications when your backup includes things like filestream or In-Memory OLTP.



          But if your goal is to make a "distributable" backup that will do all that work for the end user, I don't think a traditional SQL Server backup is what you are looking for. Maybe you should look into database projects or providing scripts instead of backups.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 '18 at 19:06

























          answered Nov 10 '18 at 15:12









          Aaron BertrandAaron Bertrand

          150k18284482




          150k18284482












          • Just to emphasize that where the database files are to be created will default to where they were when the backup was produced. So unless you can enforce a folder (the same for all your users) for where to put the database files, your users need to use the MOVE option in the RESTORE command. There's no option in the backup to say "put it in the destinations servers default database files folder".

            – Tibor Karaszi
            Nov 10 '18 at 18:37

















          • Just to emphasize that where the database files are to be created will default to where they were when the backup was produced. So unless you can enforce a folder (the same for all your users) for where to put the database files, your users need to use the MOVE option in the RESTORE command. There's no option in the backup to say "put it in the destinations servers default database files folder".

            – Tibor Karaszi
            Nov 10 '18 at 18:37
















          Just to emphasize that where the database files are to be created will default to where they were when the backup was produced. So unless you can enforce a folder (the same for all your users) for where to put the database files, your users need to use the MOVE option in the RESTORE command. There's no option in the backup to say "put it in the destinations servers default database files folder".

          – Tibor Karaszi
          Nov 10 '18 at 18:37





          Just to emphasize that where the database files are to be created will default to where they were when the backup was produced. So unless you can enforce a folder (the same for all your users) for where to put the database files, your users need to use the MOVE option in the RESTORE command. There's no option in the backup to say "put it in the destinations servers default database files folder".

          – Tibor Karaszi
          Nov 10 '18 at 18:37

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f222254%2fhow-to-make-a-distibutable-bak-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

          Crossroads (UK TV series)

          ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế