Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> Linux系統教程 >> Linux教程 >> 備份文件和目錄,並將備份文件傳送到windows的腳本

備份文件和目錄,並將備份文件傳送到windows的腳本

日期:2017/2/7 14:39:02      編輯:Linux教程
 

用途:文件備份
描述:備份文件和目錄,並將備份文件傳送到windows的腳本。
用法:腳本名 /home backup abc123 //server2000/backup


#!/bin/bash
# what do you want back
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/$BACKDIR ] && 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

Copyright © Windows教程網 All Rights Reserved