How to make a distibutable .bak file?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
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 |
up vote
1
down vote
favorite
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 |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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 at 15:00
Goncalo Peres
135113
135113
asked Nov 10 at 14:23
Eleonora Grigoryan
56813
56813
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
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 at 18:37
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
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 at 18:37
add a comment |
up vote
2
down vote
accepted
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 at 18:37
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
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 at 19:06
answered Nov 10 at 15:12
Aaron Bertrand♦
148k18280480
148k18280480
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 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 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 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 at 18:37
add a comment |
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