Create a Shared SQL Server Backups Folder on Linux

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

Syntaxsudo apt-get install samba

01-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>

02addusertosambaandchangepassword

Create a SQL Backup folder

  • Let’s check, If you have any SQL backup directory at /var/opt/ location

Syntaxls -l     (It will list down all the directory inside the current directory)

 03verify-the-location

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  

04createsqlbackupfolder

  • 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)

05changeuserownergroup

  • 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

06giverreadwriteandexecuterights

Syntax: BACKUP DATABASE TEST TO DISK  = ‘/var/opt/sqlbackups/test.bak’

10takesqlbackup

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

05sambaconfig

  • Go to the end of the configuration file by hitting “PageDown” button.

06endofthesambaconfigurationfile

  • Hit “Insert” button, and it allows you to edit the configuration file

07insertbutton

  • 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

07configuresambaconfigfile

  • Once you added the above parameters, kindly press “Esc” button, type “:wq” and hit “enter”. It saves the configuration.

08savesambaconfigfile

  • Now restart the Samba service.

Syntaxsudo service smbd restart

09restartsambaservice

Access the shared folder from Windows host

  • Get the IP of the Ubuntu Server

Syntaxifconfig

10checkipofubuntuserver

  • Go to your Windows machine, open the Run dialog box and navigate the location

11runbutton

  • You can see the folder which you shared on Linux machine.

11networkpath

  • Access the folder by keying username and password which you set to Samba. In my case, the username is “sachit”

13keypassword2

  • We can see the backup which we took at the shared location

16backupfile

  • Let’s create a text file “Created_A_TextFile.txt”

14createdatextfile

  • Verify the created file from the Linux machine.

15verifythefilefromlinuxmachine

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

  • Sai

    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

    Reply
  • Dharmendra

    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.

    Reply
    • Dharmendra

      Sai, I tried but I didn’t encounter any error. can you please share the error which you are seeing?

      Reply

Leave a comment

Your email address will not be published. Required fields are marked *