在linux风行的今天,与windows机器相互共享文件已经是非常普遍的应用了,关于samba的设置的文档也相当的多,本站也有不少了。不过在使用它的高级功能方面还是比较欠缺的,这类文档是非常稀有的,而且只有英文版的,为了方便国内的linux用户,我将这些文档整理一下,翻译过来,并结合自己一些经验,为大家提供一些帮助。
注:这篇文章并不是一篇关于如何配置samba的基础文档,而是需要阅读者有一定的linux使用经验,熟悉脚本语言,并且对samba有一定的使用经验。主要是针对于一些企业的linux网管,或比较有经验的linux爱好者。
这篇文章也其说是文章,不如说是一个技巧提示,但是我个人觉得它意义非常大,特别是对于大中型企业的用户来讲,它可能非常重要。
它主要描述了如果在linux下使用samba来为使用windows系统的机器作备份,并且描述了如何跨子网共享samba。
1、将windows机器备分到一台linux主机上
adam neat(adamneat@ipax.com.au),向我们提供了以下一段代码,它描述了如何使用smbclient软件包将windows机器备份到linux主机上。adam说它可以用来备份windows 3.x和nt机器到一台linux的磁带机上。
另一段代码,是dan tager (dtager@marsala.com),提供的,dan的脚本是通过rsh来备份unix机器,尽管它可以修改成ssh以便使其更简单些。
在下面这个脚本中,字符串“agnea1”是作备份工作的linux主机的一个用户名。
#!/bin/bash
clear
echo initialising ...
checkdate=`date awk '{print $1}'`
if [ -f "~agnea1/backup-dir/backup-data" ]; then
echo "error: no config file for today!"
echo "fatal!"
exit 1
fi
if [ -d "~agnea1/backup-dir/temp" ]; then
echo "error: no tempoary directory found!"
echo
echo "attempting to create"
cd ~agnea1
cd backup-dir
mkdir temp
echo "directory made - temp"
fi
if [ "$1" = "" ]; then
echo "error: enter in a machine name (ie: cdwriter)"
exit 1
fi
if [ "$2" = "" ]; then
echo "error: enter in a smb (lan manager) resource (ie: work)"
exit 1
fi
if [ "$3" = "" ]; then
echo "error: enter in an ip address for $1 (ie:
130.xxx.xxx.52)" exit 1
fi
######################################################################
# main section
#
######################################################################
cd ~agnea1/backup-dir/temp
rm -r ~agnea1/backup-dir/temp/*
cd ~agnea1/backup-dir/
case "$checkdate"
in
mon)
echo "backuping for monday"
cat backup-data /usr/local/samba/bin/smbclient
$1$2 -i$3 -n echo "complete"
if [ -d "~agnea1/backup-dir/monday" ]; then
echo "directory monday not found ...
making" mkdir
~agnea1/backup-dir/monday
fi
echo "archiving ..."
cd ~agnea1/backup-dir/temp
tar -cf monday.tar * echo "done ..."
rm ~agnea1/backup-dir/monday/monday.tar
mv monday.tar ~agnea1/backup-dir/monday
;;
tue)
echo "backuping for tuesday"
cat backup-data /usr/local/samba/bin/smbclient
$1$2 -i$3 -n echo "complete"
if [ -d "~agnea1/backup-dir/tuesday" ]; then
echo "directory tuesday not found ...
making" mkdir
~agnea1/backup-dir/tuesday
fi
echo "archiving ..."
cd ~agnea1/backup-dir/temp
tar -cf tuesday.tar *
echo "done ..."
rm ~agnea1/backup-dir/tuesday/tuesday.tar
mv tuesday.tar ~agnea1/backup-dir/tuesday
;;
wed)
echo "backuping for wednesday"
cat backup-data /usr/local/samba/bin/smbclient
$1$2 -i$3 -n echo "complete"
if [ -d "~agnea1/backup-dir/wednesday" ]; then
echo "directory wednesday not found
... making" mkdir
~agnea1/backup-dir/wednesday
fi
echo "archiving ..."
cd ~agnea1/backup-dir/temp
tar -cf wednesday.tar *
echo "done ..."
rm ~agnea1/backup-dir/wednesday/wednesday.tar
mv wednesday.tar ~agnea1/backup-dir/wednesday
;;
thu)
echo "backuping for thrusday"
cat backup-data /usr/local/samba/bin/smbclient
$1$2 -i$3 -n echo "complete"
if [ -d "~agnea1/backup-dir/thursday" ]; then
echo "directory thrusday not found ...
making" mkdir
~agnea1/backup-dir/thursday
fi
echo "archiving ..."
cd ~agnea1/backup-dir/temp
tar -cf thursday.tar *
echo "done ..."
rm ~agnea1/backup-dir/thursday/thursday.tar
mv thursday.tar ~agnea1/backup-dir/thursday
;;
fri)
echo "backuping for friday"
cat backup-data /usr/local/samba/bin/smbclient
$1$2 -i$3 -n echo "complete"
if [ -d "~agnea1/backup-dir/friday" ]; then
echo "directory friday not found ...
making" mkdir
~agnea1/backup-dir/friday
fi
echo "archiving ..."
cd ~agnea1/backup-dir/temp
tar -cf friday.tar *
echo "done ..."
rm ~agnea1/backup-dir/friday/friday.tar
mv friday.tar ~agnea1/backup-dir/friday
;;
*)
echo "fatal error: unknown variable passed for day"
exit 1;;
esac
###########
______________________________________________________________________
这里是dan的备份脚本:
______________________________________________________________________
#!/bin/bash
backdir=3d/backup
wincmd=3d/usr/bin/smbclient
function copywinhost(){
# tars and gzips "windows shares" to a local directory using samba's
# smbclient
# argument 1 is the remote host window's host name
# argument 2 is the share name to be backed up
echo $1,$2,$3
remote=3d$1
share=3d$2
dest=3d$3
# create a tarred gzip file using samba to copy direct from a
# windows pc
# 12345 is a password. needs some password even if not defined on
# remote system
$wincmd $remote$share 12345 -tc -gzip > $dest
echo `date`": done backing up "$remote" to "$dest
echo
}
function copyunixhost(){
# tars and gzips a directory using rsh
# argument 1 is the name of the remote source host
# argument 2 is the full path to the remote source directory
# argument 3 is the name of the local tar-gzip file. day of week
# plus .tgz will be appended to argument 3
remote=3d$1
src=3d$2
dest=3d$3
if rsh $remote tar -cf - $src gzip > $dest; then
echo `date`": done backing up "$remote":"$src" to "$dest
else
echo `date`": error backing up "$remote":"$src" to "$dest
fi
}
# $1: win=3dbackup windows machine, unix=3dbackup unix machine
case $1 in
win)
# $2=3d remote windows name, $3=3dremote share name,
# $4=3dlocal destination directory
copywinhost $2 $3 $4;;
unix)
# $2 =3d remote host, $3 =3d remote directory,
# $4 =3d destination name
copyunixhost $2 $3 $4;;
esac
______________________________________________________________________
以上两个文件都是针对于具体的机器而设计的,如果您准备对自己的机器也进行备份,那么请您安照您自己的机器的具体情况来修改这两个文件的一个,就可以使用了。
2、跨子网使用samba
许多大型企业有不同的子网,但是如何将另一个子网的内容被其它子网共享,是一个非常关键的问题,许多samba的用户在这里遇到许多麻烦,如果这点被解决了,那么可以使资源利用率大大提高。使企业的成本降低不少。
andrew tridgell声称smb主机在通过有路由的网络共享时有一些问题。这是他的一些建议:
跨子网(例如,通过路由)资源浏览,你需要作以下事情。
1.所有希望被浏览的的计算机应该使用一个单个的wins服务器(samba或nt可以作到这点)
2.每个子网的master brower必须不是nt就是samba。(win9x不能正常地跨子网工作通讯)
3.你必须将所有子网的workgroup名字都设成一样的。这并不需要非常严格地遵守,但是这是保证成功的最简单的方式之一。如果你不能遵守这一条,那么你必须组织一种可以连接两个网络的方式,它可以由两种方式实现:
(1)每个browse master注意到在同一广播域中其它的borwse masters的workgroup的描述(2)每个非win9x的browse master要接触全部workgroup的dmb(常用的有:将主域控制器或一个samba服务器标记为domain master),并且周期性地交换browse 信息。
当然,其它用户指出,cisco的路由器可以通过一种方式被设置成解析smb的交流,并允许浏览。它的建议是将smb主机的路由接口设置成:
ip helper-address x.x.x.x
这里x.x.x.x是这台smb服务器的ip地址。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器