2011-01-12 32 views
1

私はWindows PCからバックアップ共有に小さなbash(4)スクリプトを書いています。現在、私は1つの共有のみをバックアップしています。バックアップはrootにしか見えません。株式有無などの条件が、馬鹿を作るために(ポイントの存在をマウントする場合rsyncを使ったsamba共有用のbashバックアップスクリプトの参考書

  1. がチェック:

    #!/bin/bash 
    # Script to back up directories on several windows machines 
    # Permissions, owners, etc. are preserved (-av option) 
    # Only differences are submitted 
    # Execute this script from where you want 
    
    # Make sure only root can run our script 
    if [ "$(id -u)" != "0" ]; then 
        echo "This script must be run as root" 1>&2 
        exit 1 
    fi 
    
    # Specify the current date for the log-file name 
    current_date=$(date +%Y-%m-%d_%H%M%S) 
    
    # Specify the path to a list of file patterns not included in backup 
    script_path=$(dirname $(readlink -f $0)) 
    rsync_excludes=$script_path/rsync_exclude.patterns 
    
    # Specify mount/rsync options 
    credential_file="/root/.smbcredentials" 
    # Specify windows shares 
    smb_shares=(//192.168.0.100/myFiles) 
    # Specify the last path component of the directory name to backup shares 
    # content into 
    smb_share_ids=("blacksmith") 
    # Specify with trailing '/' to transfer only the dir content 
    rsync_src="/mnt/smb_backup_mount_point/" 
    rsync_dst_root=(~/BACKUPS) 
    
    # Check if all arrays have the same size 
    if [ "${#smb_shares[@]}" -ne "${#smb_share_ids[@]}" ]; then 
        echo "Please specify one id for each samba share!" 
        exit 1 
    fi 
    
    # Run foor loop to sync all specified shares 
    for ((i = 0 ; i < ${#smb_shares[@]} ; i++)) 
    do 
        # Check if mount point already exists 
        echo -n "Checking if mount point exists ... " 
        if [ -d $rsync_src ]; then 
        echo "Exists, exit!" 
        exit 1 
        else 
        echo "No, create it" 
        mkdir $rsync_src 
        fi 
    
        # Try to mount share and perform rsync in case of success 
        echo -n "Try to mount ${smb_shares[$i]} to $rsync_src ... " 
        mount -t cifs ${smb_shares[$i]} $rsync_src -o credentials=/root/.smbcredentials,iocharset=utf8,uid=0,file_mode=0600,dir_mode=0600 
        if [ "$?" -eq "0" ]; then 
        echo "Success" 
    
        # Specify the log-file name 
        rsync_logfile="$rsync_dst_root/BUP_${smb_share_ids[$i]}_$current_date.log" 
    
        # Build rsync destination root 
        rsync_dst=($rsync_dst_root"/"${smb_share_ids[$i]}) 
    
        # Check if rsync destination root already exists 
        echo -n "Check if rsync destination root already exists ... " 
        if [ -d $rsync_dst ]; then 
         echo "Exists" 
        else 
         echo "Does not exist, create it" 
         mkdir -p $rsync_dst 
        fi 
    
        # Run rsync process 
        # -av     > archieve (preserve owner, permissions, etc.) and verbosity 
        # --stats    > print a set of statistics showing the effectiveness of the rsync algorithm for your files 
        # --bwlimit=KBPS  > transfer rate limit - 0 defines no limit 
        # --progress   > show progress 
        # --delete    > delete files in $DEST that have been deletet in $SOURCE 
        # --delete-after  > delete files at the end of the file transfer on the receiving machine 
        # --delete-excluded  > delete excluded files in $DEST 
        # --modify-window  > files differ first after this modification time 
        # --log-file   > save log file 
        # --exclude-from  > exclude everything from within an exclude file 
        rsync -av --stats --bwlimit=0 --progress --delete --delete-after --delete-excluded --modify-window=2 --log-file=$rsync_logfile --exclude-from=$rsync_excludes $rsync_src $rsync_dst 
        fi 
    
        # Unmount samba share 
        echo -n "Unmount $rsync_src ... " 
        umount $rsync_src 
        [ "$?" -eq "0" ] && echo "Success" 
    
        # Delete mount point 
        echo -n "Delete $rsync_src ... " 
        rmdir $rsync_src 
        [ "$?" -eq "0" ] && echo "Success" 
    
    
    done 
    

    は、今私は、次のトピックに関するいくつかの助けを必要とする:コードのその部分の改善のために私にいくつかのヒントを教えてください証明スクリプト)

  2. マウントコマンド - それは正しいです、私は正しいアクセス許可を与えますか?
  3. rootだけがそのファイルを見ることができる場合、バックアップファイルの場所は、ユーザーのホームディレクトリよりも適していますか?
  4. 他のファイルシステムのバックアップも統合すると便利だと思いますか?
  5. 私はギガビットネットワークシステムを持っていますが、バックアップはかなり遅いです(約13mb/s)。これはおそらくrsyncのssh暗号化のためですか?共有がマウントされているLinuxシステムには、pci sataコントローラと古いメインボード、1GB RAM、athlon xp 2400+があります。遅さの理由は他にもありますか?

ここで取り上げることができるトピックがたくさんある場合は、投稿してください。私が興味を持っています=)

乾杯

-Blackjacx

答えて

0

1)あなたは、このスクリプトをより堅牢にするために行うことができますエラーチェックがたくさんある:existanceをチェックして、外部の実行ファイルの状態を実行し( rsync、id、date、dirnameなど)、rsyncの出力を確認して([0 -ne $?]とした場合)、リモートマシンにpingを実行してネットワークに接続していることを確認し、あなたはローカルマシン上にホームディレクトリを持っているバックアップを行い、rsyncなどに十分なスペースがあるかどうかを確認してください。

2)mou NTコマンドは大丈夫ですが、読み込み専用としてマウントしようとしましたか?

3)ユーザー数とバックアップのサイズによって異なります。小規模なバックアップの場合、ホームディレクトリは大丈夫ですが、バックアップが大きい場合、特にディスク容量が足りなくなった場合は専用のバックアップ場所が良いでしょう。

4)バックアップの目的によって異なります。私の経験では、ユーザーデータ、システムデータ、ユーザー構成、システム構成、ディスク全体またはファイルシステムの5種類のバックアップがあります。システムデータと構成をバックアップする別個のシステムタスクはありますか?

5)バックアップ中に実行されている他のタスクはありますか?バックアップが午前1時に自動化されて実行されている場合、他のシステム集中型タスクが同時にスケジュールされている可能性があります。他の種類のデータの典型的なスループット・レートはどれくらいですか?

配列以外の変数に対して配列チェックを実行しています。

変数を使用してリモートマシンを指定します。

rsync_srcはこれだけmackupのために使用されている場合は、

ping -c 1 $remote_machine 
if [ 0 -ne $? ] ; then 
    echo "ping on $remote_machine Failed, exiting..." 
    exit 1 
fi 

、あなたが

mnt_dir="/mnt" 
rsync_src=`mktemp -d -p $mnt_dir` 

をしようとするWATかもしれないことができると私は、そうでない場合のためにループする前にこのディレクトリを作るような方法

# Remote machine 
declare remote_machine="192.168.0.100" 
# Specify windows shares array 
declare -a smb_shares=([0]="//$remote_machine/myFiles" 
         [1]="//$remote_machine/otherFiles") 
# Specify the last path component of the directory name to backup shares 
# content into 
declare -a smb_share_ids=([1]="blacksmith" [2]="tanner") 

バックアップするすべてのディレクトリに対して作成および破棄しています。

関連する問題