Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore a database from bak file from azure data studio on Mac

Previously on Mac I use mysql operation studio and I click on database and click restore then browse to my bak file, but now they change to azure data studio and when I repeat the same steps I got this error: "You must enable preview features in order to use restore" enter image description here but I cannot figure out hot to enable that. I have googled and tried few things even open my azure, microsoft account on website but I do not see that option. Can some one help please !

like image 844
user1314404 Avatar asked Nov 28 '18 07:11

user1314404


People also ask

How do you restore from a .BAK file in Azure Data Studio for Mac?

Restore a database from a backup file Then right-click your server, and select Manage. Open the Restore database dialog box by selecting Restore on the Tasks widget. Select Backup file in the Restore from box.

How do I restore a database from a BAK file?

Restore the database from a BAK fileRight-click on the database server in the left navigation pane, click Tasks, click Restore. The name of the restoring database appears in the To database list box. To create a new database, enter its name in the list box. Select 'From device'.


2 Answers

  • Go to Azure Data Studios > Settings
  • Edit settings by clicking on "new settings editor"
  • Search for "preview"
  • Scroll to the bottom and check "Enable unreleased preview features"
like image 100
user1705135 Avatar answered Sep 21 '22 14:09

user1705135


Adding this as an answer as I don't have enough rep to comment. This is in response to the question in the comment for the answer to the OP (If that's not confusing enough!)

This only applies when your sql database is hosted on a Mac/Linux/Docker Container. We don't have any Windows servers in our estate for me to test this on to see if the location of the .bak files is any different.

When you click on the "..." button, it browses to /var/opt/mssql/data on the machine (or docker container) the database is hosted on. This is not an issue if you are backing up & restoring databases on the same host, however, if you're migrating to a new server or just creating a dev/UAT/staging environment, it becomes a problem because you don't have access to var/opt/mssql/data.

This is a bit of a sledgehammer to crack a nut type solution but as I'm working with 2 dev boxes, it doesn't make a lot of difference to me.

To make this easier to understand I'll call the server that hosts the database you have backed up ProdServ & the server you are restoring to DevServ.

On DevServ, at a terminal prompt, navigate to /var/opt and make a note of the current permissions on the mssql directory (mine were drwxrwx---).

$ cd /var/opt

$ ls -la

Google the octal value for your permissions (in my instance, it's 770)

Change the permissions of the data directory to rwxrwxrwx.

$ chmod -R 777 /var/opt/mssql/data

(You will also need to do this on ProdServ if that is also a Unix-based o/s)

Copy the .bak files from ProdServ to DevServ via a method suitable to the environment you're working in.

Windows --> Linux I'd use WinSCP

For Mac to Docker, docker cp <fileToCopy> <container>:<destinationPath> works perfectly fine.

Once the files have been copied over, they will magically appear when you click the "..." button in azure data studio again. Make sure you change the directory permissions back to their original value via the same command. So in my instance, simply

$ chmod -R 770 /var/opt/mssql/data

As an extra note, if you're used to working in MSSMS, the wizard there allows you to create a database from a .bak file, from what I can see, Azure Data Studio does not. You have to create the database first (CREATE DATABASE <databasename>) in a query window, then restore the .bak file to it.

like image 45
Lex Avatar answered Sep 21 '22 14:09

Lex