To Transfer files from Windows to Linux (Ubuntu) or vice versa, you can use Samba to create a shared folder on the Linux system. This allows the files to be shared on the network through the SMB protocol. This will also allow Windows hosts to get access remote to the files using file explorer.
We are going to walkthrough a step-by-step installation and configuration of the Samba so that you can easily share the files between different operating systems.
Install Samba on Ubuntu
- Connect to the Linux server as root user and install the Samba package by running below command
Syntax: sudo apt-get install samba
- Once you installed the Samba package, you’ll need to add a local user to Samba and assign a new password to it. You will be using the user account to access the shared folder from a remote location.
Syntax: sudo smbpasswd -a <username>
Create a SQL Backup folder
- Let’s check, If you have any SQL backup directory at /var/opt/ location
Syntax: ls -l (It will list down all the directory inside the current directory)
The output confirms that we don’t have any SQL Backup folder under opt.
- Create a sqlbackups folder at /var/opt location and verify it
Syntax: sudo mkdir /var/opt/sqlbackups (It will create the directory)
Syntax: ls -l
- Since the created folder is owned by root – user and group user, it can’t be accessed by a non-root user. You need to change the ownership of the folder by running following commands
Syntax: sudo chown mssql /var/opt/sqlbackups (It changes the user ownership)
Syntax: sudo chgrp mssql /var/opt/sqlbackups (It changes the group user ownership)
- Give a read, write and execute permission on the folder to the local user (sachit) which you added to Samba in the earlier steps. The permissions will allow the user to create, copy, paste and delete files from a Windows machine.
Syntax: setfacl -m u:<username>:rwx /var/opt/sqlbackups
- Connect to SQL Server Linux Instance and take a backup of SQL Server database at the shared location.
Syntax: BACKUP DATABASE TEST TO DISK = ‘/var/opt/sqlbackups/test.bak’
Change the Samba configuration file
Now, we need to modify the Samba configuration file using a text editor. I will be using “vim” text editor to edit the configuration file.
- Open the configuration file in vim text editor
Syntax: sudo vim /etc/samba/smb.conf
- Go to the end of the configuration file by hitting “PageDown” button.
- Hit “Insert” button, and it allows you to edit the configuration file
- Add the below mentioned parameters to the configuration file.
Syntax:
[sql_backup]
path = /var/opt/sqlbackups
valid users = <username>
read only = no
browsable = yes
writable = yes
- Once you added the above parameters, kindly press “Esc” button, type “:wq” and hit “enter”. It saves the configuration.
- Now restart the Samba service.
Syntax: sudo service smbd restart
Access the shared folder from Windows host
- Get the IP of the Ubuntu Server
Syntax: ifconfig
- Go to your Windows machine, open the Run dialog box and navigate the location
- You can see the folder which you shared on Linux machine.
- Access the folder by keying username and password which you set to Samba. In my case, the username is “sachit”
- We can see the backup which we took at the shared location
- Let’s create a text file “Created_A_TextFile.txt”
- Verify the created file from the Linux machine.
You can easily move files from Windows machine to Linux machine or vice versa. The Samba package makes life easier for DBAs. Hope, you find this post informative and useful.
3 thoughts on “Create a Shared SQL Server Backups Folder on Linux”
Hello Dharmendra,
I am a full time Masters level student from Michigan, USA. I have been following all of your videos for the last couple of months and fascinated to learn mssql in Linux. Till date, it went calm and easy but today I found difficult to install samba on my personal machine. I have tried the syntax (sudo apt-get install samba) which you have mentioned in this article and video which you have presented in 2016 at Singapore. But, I couldn’t fix the issue. Hope you can help to fix it.
Hope to hear soon from you
Thank you
Sai
Hi Sai, Glad to hear that you liked the contents. May you please share what error you are facing? I will try to procedure the error. You will be hearing back from me after 18th Fab.
Sai, I tried but I didn’t encounter any error. can you please share the error which you are seeing?