专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>shell脚本欣赏>

shell脚本(功能:备份Linux Server文件到Windows 2000/NT Server服务器上)

百度收藏 QQ搜藏

原文:http://bash.cyberciti.biz/backup/backup-directories-from-linux-to-windows-server/

以下是该shell脚本的源代码:

#!/bin/bash
# Shell script to backup directories from Linux server to Windows 2000/NT Server.
# Run it as follows
# Scriptname /home backup abc123 //server2000/backup
# Backup /home directory from Linux box  to NT/2000 box called
# 'server2000' in share called '/backup' with username
# 'backup' and password 'abc123'
# --------------------------------------------------------------------
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2005 nixCraft project
# Feedback/comment/suggestions : http://cyberciti.biz/fb/
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection 
(NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
# backup what?
FROM=$1
# NT Connection Info #
# NT Username
NTUSER=$2
# NT Password
NTPASSWD=$3
# NT ShareName i.e //server/backup etc
NTSHARE="$4"
 
# BackUpDir Name
BACKDIR="$(hostname -s)
"
 
# Local mount point
MNT="/mnt/smbbox"
 
# Get date and time
NOW=$(date +"%m-%d-%Y-%I_%M%P")
# backup file  name
BAKFILE="backup.$NOW.tar.gz"
 
if [ "$#" != "4" ]; then
	echo "Syntax:"
	echo "$(basename $0) {Linux-directory} {NTusername} {NTpassword} {//NTserver/share-name}"
	exit 1
fi
# make sure $from do exits
if [ ! -d $FROM ]; then
   echo "Backup source directory \"$FROM\" does NOT exist"
   exit 2
fi
#Create tar to backup first
tar -czf /tmp/$BAKFILE $FROM 
 
#Mount the smb to /mnt
[ ! -d $MNT ] && mkdir -p $MNT || :
 
mount -t smbfs -o username=$NTUSER,password=$NTPASSWD $NTSHARE $MNT
 
[ ! -d $MNT/$BACKUPDIR ] && mkdir -p $MNT/$BACKDIR || :
 
# Copy new tar to ntbox
cp /tmp/$BAKFILE $MNT/$BACKDIR 
# Send sync aka force to write data before issuing umount
sync
 
# issue umount
umount $MNT
上一篇:Shell脚本(功能:备份压缩用户目录所有文件成.tar.gz格式并发送到邮箱) 下一篇:shell脚本(功能:备份Mysql数据库数据)

power by soyo123 2007-2008