在Linux風行的今天
與Windows機器相互共享文件已經是非常普遍的應用了
關於samba的設置的文檔也相當的多
本站也有不少了
不過在使用它的高級功能方面還是比較欠缺的
這類文檔是非常稀有的
而且只有英文版的
為了方便國內的Linux用戶
我將這些文檔整理一下
翻譯過來
並結合自己一些經驗
為大家提供一些幫助
注
這篇文章並不是一篇關於如何配置samba的基礎文檔
而是需要閱讀者有一定的Linux使用經驗
熟悉腳本語言
並且對samba有一定的使用經驗
主要是針對於一些企業的Linux網管
或比較有經驗的Linux愛好者
這篇文章也其說是文章
不如說是一個技巧提示
但是我個人覺得它意義非常大
特別是對於大中型企業的用戶來講
它可能非常重要
它主要描述了如果在Linux下使用samba來為使用Windows系統的機器作備份
並且描述了如何跨子網共享samba
將Windows機器備分到一台Linux主機上
Adam Neat(
au)
向我們提供了以下一段代碼
它描述了如何使用smbclient軟件包將windows機器備份到Linux主機上
Adam說它可以用來備份windows
x和NT機器到一台Linux的磁帶機上
另一段代碼
是Dan Tager ()
提供的
Dan的腳本是通過rsh來備份Unix機器
盡管它可以修改成ssh以便使其更簡單些
在下面這個腳本中
字符串
agnea
是作備份工作的Linux主機的一個用戶名
#!/bin/bash
clear
echo Initialising
checkdate=`date | awk
{print $
}
`
if [
f
~agnea
/backup
dir/backup
data
]; then
echo
ERROR: No config file for today!
echo
FATAL!
exit
fi
if [
d
~agnea
/backup
dir/temp
]; then
echo
ERROR: No tempoary directory found!
echo
echo
Attempting to create
cd ~agnea
cd backup
dir
mkdir temp
echo
Directory Made
temp
fi
if [
$
=
]; then
echo
ERROR: enter in a machine name (ie: cdwriter)
exit
fi
if [
$
=
]; then
echo
ERROR: enter in a SMB (Lan Manager) Resource (ie: work)
exit
fi
if [
$
=
]; then
echo
ERROR: enter in an IP address for $
(ie:
xxx
xxx
)
exit
fi
#########################################################
# Main Section
#
#########################################################
cd ~agnea
/backup
dir/temp
rm
r ~agnea
/backup
dir/temp/*
cd ~agnea
/backup
dir/
case
$checkdate
in
Mon)
echo
Backuping for Monday
cat backup
data | /usr/local/samba/bin/smbclient
$
$
I$
N echo
Complete
if [
d
~agnea
/backup
dir/Monday
]; then
echo
Directory Monday Not found
making
mkdir
~agnea
/backup
dir/Monday
fi
echo
Archiving
cd ~agnea
/backup
dir/temp
tar
cf monday
tar *echo
done
rm ~agnea
/backup
dir/Monday/monday
tar
mv monday
tar ~agnea
/backup
dir/Monday
;;
Tue)
echo
Backuping for Tuesday
cat backup
data | /usr/local/samba/bin/smbclient
$
$
I$
N echo
Complete
if [
d
~agnea
/backup
dir/Tuesday
]; then
echo
Directory Tuesday Not found
making
mkdir
~agnea
/backup
dir/Tuesday
fi
echo
Archiving
cd ~agnea
/backup
dir/temp
tar
cf tuesday
tar *
echo
done
rm ~agnea
/backup
dir/Tuesday/tuesday
tar
mv tuesday
tar ~agnea
/backup
dir/Tuesday
;;
Wed)
echo
Backuping for Wednesday
cat backup
data | /usr/local/samba/bin/smbclient
$
$
I$
N echo
Complete
if [
d
~agnea
/backup
dir/Wednesday
]; then
echo
Directory Wednesday Not found
making
mkdir
~agnea
/backup
dir/Wednesday
fi
echo
Archiving
cd ~agnea
/backup
dir/temp
tar
cf wednesday
tar *
echo
done
rm ~agnea
/backup
dir/Wednesday/wednesday
tar
mv wednesday
tar ~agnea
/backup
dir/Wednesday
;;
Thu)
echo
Backuping for Thrusday
cat backup
data | /usr/local/samba/bin/smbclient
$
$
I$
N echo
Complete
if [
d
~agnea
/backup
dir/Thursday
]; then
echo
Directory Thrusday Not found
making
mkdir
~agnea
/backup
dir/Thursday
fi
echo
Archiving
cd ~agnea
/backup
dir/temp
tar
cf thursday
tar *
echo
done
rm ~agnea
/backup
dir/Thursday/thursday
tar
mv thursday
tar ~agnea
/backup
dir/Thursday
;;
Fri)
echo
Backuping for Friday
cat backup
data | /usr/local/samba/bin/smbclient
$
$
I$
N echo
Complete
if [
d
~agnea
/backup
dir/Friday
]; then
echo
Directory Friday Not found
making
mkdir
~agnea
/backup
dir/Friday
fi
echo
Archiving
cd ~agnea
/backup
dir/temp
tar
cf friday
tar *
echo
done
rm ~agnea
/backup
dir/Friday/friday
tar
mv friday
tar ~agnea
/backup
dir/Friday
;;
*)
echo
FATAL ERROR: Unknown variable passed for day
exit
;;
esac
###########
______________________________________________________
這裡是Dan的備份腳本
______________________________________________________
#!/bin/bash
BACKDIR=
D/backup
WINCMD=
D/usr/bin/smbclient
function CopyWinHost(){
# tars and gzips
windows shares
to a local directory using samba
s
# smbclient
# argument
is the remote host window
s host name
# argument
is the share name to be backed up
echo $
$
$
REMOTE=
D$
SHARE=
D$
DEST=
D$
# create a tarred gzip file using samba to copy direct from a
# windows pc
#
is a password
Needs some password even if not defined on
# remote system
$WINCMD $REMOTE$SHARE
Tc
|gzip > $DEST
echo `date`
: Done backing up
$REMOTE
to
$DEST
echo
}
function CopyUnixHost(){
# tars and gzips a directory using rsh
# argument
is the name of the remote source host
# argument
is the full path to the remote source directory
# argument
is the name of the local tar
gzip file
day of week
# plus
tgz will be appended to argument
REMOTE=
D$
SRC=
D$
DEST=
D$
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
}
# $
: win=
Dbackup windows machine
unix=
Dbackup unix machine
case $
in
win)
# $
=
D remote windows name
$
=
Dremote share name
# $
=
Dlocal destination directory
CopyWinHost $
$
$
;;
unix)
# $
=
D remote host
$
=
D remote directory
# $
=
D destination name
CopyUnixHost $
$
$
;;
esac
以上兩個文件都是針對於具體的機器而設計的
如果您准備對自己的機器也進行備份
那麼請您安照您自己的機器的具體情況來修改這兩個文件的一個
就可以使用了
跨子網使用samba
許多大型企業有不同的子網
但是如何將另一個子網的內容被其它子網共享
是一個非常關鍵的問題
許多samba的用戶在這裡遇到許多麻煩
如果這點被解決了
From:http://tw.wingwit.com/Article/program/Oracle/201311/16849.html