How to make a distibutable .bak file?
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
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
add a comment |
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
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
add a comment |
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
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
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
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
sql-server backup restore
edited Nov 10 '18 at 15:00
Goncalo Peres
133114
133114
asked Nov 10 '18 at 14:23
Eleonora GrigoryanEleonora Grigoryan
58114
58114
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
edited Nov 10 '18 at 19:06
answered Nov 10 '18 at 15:12
Aaron Bertrand♦Aaron 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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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