Mounting Windows shares on Linux
Wednesday, August 22nd, 2007
Recently I had the need to back up my cvs root directory that lives on our Linux dev server to a Windows server. It wasn't as straight forward as you might think, so I thought that I would share my solution. At first I tried to mount an NFS Windows share to my Linux box, but because we don't have an NIS server I am not able to authenticate my Linux account against my Windows account. Most of you developers out there that have to support yourselves will probably have this issue because most office IT infrastructures are Windows based which don't always play nice with your Linux dev box.
I ended up creating a folder on the Windows server and sharing it, although I did have to end up giving read/write permissions to Everybody. Our development environment is secure so I'm not worried about it, but otherwise this could get you in trouble with your sys admin. This is all the set-up that is necessary on the Windows side. Now lets flip over to the Linux box and set it up.
To mount the share you first have to edit the /ect/fstab file which contains information about the file systems available and their mount options. Add the following line to the file:
server/share, mount directory, filesystem type, mount options, dump, fsck
Next we need to create the directory
You can find more information on mounting windows shares here.
And for additional rsync examples and the inspiration behind my backup script go here.
I ended up creating a folder on the Windows server and sharing it, although I did have to end up giving read/write permissions to Everybody. Our development environment is secure so I'm not worried about it, but otherwise this could get you in trouble with your sys admin. This is all the set-up that is necessary on the Windows side. Now lets flip over to the Linux box and set it up.
To mount the share you first have to edit the /ect/fstab file which contains information about the file systems available and their mount options. Add the following line to the file:
//<windows server>/<name of share> /mnt/<name of directory to mount share to> cifs uid=<linux username>,credentials=/etc/cifspw,domain=<name of domian> 0 0The line has several space separated fields:
server/share, mount directory, filesystem type, mount options, dump, fsck
Next we need to create the directory
/mnt/<name of directory to mount share to> which the mount command will need to be successful. Then the last thing before we can mount the Windows share is to create the credentials file that we specified in the fstab file. In the /etc directory create the cifpw file.
# vi cifspwThen put your info in the cifspw file:
username=<windows server username> password=<windows server password>After that we are safe to mount the share:
# mount <name of directory to mount share to>/Now we're ready to set-up the backup. This is a very simple daily rotating backup script.
#!/bin/sh # source directory to backup SRCDIR=<path to directory to be backed up> # destination directory to backup to DESTDIR=/mnt/<name of directory to mount share to> # incremental directory INCDIR=`date +%A` # backup options OPTS="-av --delete --force --ignore-errors" # clears last week backup for current day [ -d $HOME/emptydir ] || mkdir $HOME/emptydir rsync --delete -a $HOME/emptydir/ $DESTDIR/$INCDIR/ rmdir $HOME/emptydir # do the backup rsync $OPTS $SRCDIR $DESTDIR/$INCDIRPut this script in /etc/cron.daily and you're done.
You can find more information on mounting windows shares here.
And for additional rsync examples and the inspiration behind my backup script go here.