Make SMB Drive accessible in terminal

I was thinking about backing up server regularly, but I wanted to backup it on remote server, so I thought how about accessing SMB drive (My Windows PC) through command line? I thought it would be easy to mount it with “smbfs”, but I was wrong. Because I was not able to transfer/create any file/folder, In short no write permission.

But I found the solution of it by Googling :)

Here are the steps to be done.

1. Know the local address of you computer of which HDD you want to mount, In my case it is 192.168.1.11

2. Make directory of any name (drive in my case).

sudo mkdir  /media/drive

3. First check if you can mount it or not.

 sudo mount -t smbfs //192.168.1.11/drive /media/drive

4. If its mountable then unmount it and  following is the step to make it Write enable.

 sudo mount -t smbfs //192.168.1.11/drive /media/drive -o uid=username,rw,owmask=0775

Here username is your username in ubuntu system (mostly admin not root).

6. Whats next? I made a shell script for that.

echo "It will mount smb location to /media/drive"
echo "Enter Option"
echo "1 to mount"
echo "2 to unmount"
echo "Enter Option"
read a
echo "Default Address 192.168.1.11"
if test $a -eq 1
then
cd /
sudo mount -t smbfs //192.168.1.11/drive /media/drive -o uid=username,rw,ownmask=0777
elif test $a -eq 2
then
sudo umount /drive
fi

I kept 777 permission, no reason for that !

7. Now if you want to backup your website regularly (only website path, not database), you can add following command in cron.

cp -rf /var/www /media/drive/backup_folder

In case you want to backup your SQL database regularly, I found a nice post.

http://www.noupe.com/how-tos/10-ways-to-automatically-manually-backup-mysql-database.html

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>