Printed from http://kimbriggs.com

Basic Samba Setup for a Home Fileserver with Nightly Backups using rsync

This tutorial uses Ubuntu 7.04 and Samba 3.0.24. There is an older one for Suse 9.3 and Samba 3.0.13.

Summary of Samba Fileserver Network Objectives

You are tired of having several copies of the same file on different computers, or figuring out which computer you have a certain file on. You have a trusted LAN, either at your home or a SOHO (Small Office Home Office) type of setup and you would like to have one central place for every person (every computer) to work off of. You may also be afraid of the Windows Home Server.

It is truly a trusted LAN and you are not concerned about security. In other words, you don't want to have to enter a username and password. You want all files to be owned by the same user on the central fileserver and be equally accessed by anybody on the network. You want it to appear that the user is working on files on the local machine.

If you have a situation similar to the above, I recommend you do like the big enterprise corporations and use linux where it is well suited and completely ready for use, as a central fileserver. This setup has saved me lots of time, some money and prevented a lot of aggravation.

Requirements:A dedicated computer that you can leave on all the time, or at least will be on when any other computer in the network is being used. An extra hard drive. A linux distribution containing the Samba package. I have described a setup using Ubuntu linux (it's free). This most likely means the method would work for Debian GNU/linux as well. A safe minimum is Pentium III and 256MB RAM. A nice fileserver would be a P4 with 500MB RAM.

Samba Background

Samba is a an open-source software package that runs on non-MS Windows machines that lets you communicate with Windows servers and clients. It can work on linux-linux machines as well, but I'm of the opinion that the NFS (Network File System) is much better suited for that task. There is a lot of documentation on the Samba website and included in the Samba package. Go to those places if you really want to learn the details.

***Do not use this method if you are concerned about protecting sensitive data***.

The Samba package for linux/UNIX is capable of enterprise-wide file sharing and handling different types of security authentication. The default setup is, in fact, very secure and it took me a while to figure out the settings for a "wide open" sharing setup, similar to the Windows Network Neighborhood defaults. I have included a summary of the settings you need to make Samba INSECURE.

Description for "How-To" Samba Fileserver based on Ubuntu Linux 7.04, Samba 3.0.24

Using the Synaptic front-end to the apt-get package management tool, it is very easy to get Samba Server up and running. Then by joining the Windows workgroup for you LAN, you're almost done. The real trick comes in modifying the Samba configuration file, /etc/samba/smb.conf. First the easy stuff:

Initial setup of linux samba fileserver and Windows samba cha-cha-cha client.

Rant on Ubuntu GUI: There is currently a terrible little "right-click" option for sharing folders in your home directory. I happen to set up NFS file sharing first because it is more full-funtional than Samba and I don't use my Windows computer that often. If you then use the right-click option to "share with" and choose "samba", IT WILL ERASE ENTRIES FOR NFS in /etc/exports! How Windows-esque of this software...yikes! Read on below how to setup sharing manually in a very easy manner.

If you are sure the computers can talk to each other (ping), and you have installed the Samba server as described above, the only other thing you need to do is replace the file /etc/samba/smb.conf with the one below. Make sure you make a backup of this file, by calling it smb.conf_ORIG or something and only work on the new one. You need to replace the values in quotes with your values and don't include the quotes. You also need to add/edit the paths if you use different directory (folder) names. After [global], the bracketed values will be the names of the shares on the network. They don't have to be the same as the directories they represent.

Restart the samba server (#sudo /etc/init.d/samba restart), and open Windows up to a wider world.

Looks pretty simple, right? There is a huge amount of information for all of the modifications and security measures you can make to samba in the original smb.conf file. I tried working with it for a while and gave up. In some debian tutorial on samba, they gave a tiny sample file to test with and I worked from that. The file comment said, "Please for testing only", so this is your last reminder that this will make your files totally INSECURE.

[global] workgroup = "workgroup_name"
server string = Samba Server
security = share
name resolve order = lmhosts hosts

[audio]
path = /home/"user_name"/audio
force user = "user_name"
force group = users
read only = no
guest ok = yes

[documents]
path = /home/"user_name"/documents
force user = "user_name"
force group = users
read only = no
guest ok = yes

[music_CDs]
path = /home/"user_name"/music_CDs
force user = "user_name"
force group = users
read only = no
guest ok = yes

[photos]
path = /home/"user_name"/photos
force user = "user_name"
force group = users
read only = no
guest ok = yes

[videos]
path = /home/"user_name"/videos
force user = "user_name"
force group = users
read only = no
guest ok = yes

[websites]
path = /home/"user_name"/public_html
force user = "user_name"
force group = users
read only = no
guest ok = yes

To make things simple: On your Windows clients, you should automatically be able to see the shares through "My Network" (Network Neighborhood). To make the files easier to access, I suggest you create shorcuts within your "My Documents" folder that is usually on the desktop. I think I remember having problems, however, substituting the actual directory "My Documents" with a shortcut. Windows kind of told me I didn't want to do that, but I was able to delete and recreate "My Music" and "My Pictures" as shortcuts to the fileserver's directories, but the name has to be exactly the same, or else Windows will keep re-creating them for you. The only drawback to this is that you will have a shortcut something like "My Documents\documents", which could mean an extra click at times. On the other hand, it helps to "cleanup" the My Documents folder into a few, high-level directories.

The lmhosts or hosts file: All I have right now is a Windows XP machine where they are kept in C:\windows\system32\drivers\etc. I can't remember if you need this for samba or not, but you'll definitely need it if you use virutal directories on your development machine (I haven't written that how-to yet).

Ex: Open up My Documents -> Empty My Pictures (because you've already got them on your fileserver, right?) and delete it -> Click File...New Shortcut -> Use the wizard to browse to the folder on the network that you want (e.g., photos) -> If it doesn't give you an opportunity to rename it, right-click the new shortcut and rename it "My Pictures".

To arrange nightly backups:

  1. Add the extra hard drive to the linux file server.
  2. Choose a nice and easy "mount point" (location) for it like "/backup".
  3. Make it writeable for the user (as root): chown -R "user_name" /backup.
  4. Create a text file (shell script) to execute the rsync program for each directory (see below).
  5. Schedule a cron job to run nightly and execute the shell script.

Contents of shell script "backup.sh". You need the trailing slash for the first location.
rsync -av /home/"user_name"/audio/ /backup/audio
rsync -av /home/"user_name"/documents/ /backup/documents
rsync -av /home/"user_name"/music_CDs/ /backup/music_CDs
rsync -av /home/"user_name"/photos/ /backup/photos
rsync -av /home/"user_name"/videos/ /backup/videos
rsync -av /home/"user_name"/public_html/ /backup/websites

Check the backup directory once in a while to clean up deleted files you are SURE you don't need. The -av options do NOT delete files. They update existing files to newer versions and add files not yet in the backup folder.

If you got this far, you might be interested in the various linux programs that are available for on your server.

It is hard to describe how much easier computer networking / maintenance has been since I installed this setup. I don't have any special interest in rsync or Ubunut linux, but they have proven to be really good products. I do have a negative view of Novell currently, as they have been supporting the Be Very Afraid Tour.

Google
 
CC License Ubuntu Bluefish Editor Graphics by GIMP Eliminate DRM Get Firefox php.net Play Ogg Valid XHTML 1.0 why the icons?