1

tar / cpを取得して、.jarで終わらないファイルと、rootおよび/ pluginsディレクトリのみをコピーするにはどうすればよいですか?

そこで、Minecraftサーバーのバックアップスクリプトを作成しています。私が望んでいるオプションの1つは、構成ファイルのみのバックアップです。シナリオは次のとおりです。

  1. に大量のデータが含まれるフォルダがたくさんあります。
  2. 構成ファイルは主に次の拡張子を使用しますが、別の拡張子を使用する場合もあります。
    • .yml
    • .json
    • 。プロパティ
    • .loc
    • .dat
    • .ini
    • 。TXT
  3. 構成ファイルは主に/pluginsフォルダーにあります
  4. ルートディレクトリにはいくつかの構成ファイルがありますが、/plugins以外にはありません。
  5. これらの2つのディレクトリにある他のファイルは、ある程度は.jarファイルだけです。これらはバックアップする必要はありません。これが、現在機能しているプラ​​グインフラグの仕事です。

このコードでは、ユーザーがプロセスを開始したフラグを組み合わせて使用tar​​します。プロセスはコマンドで開始され、次に、引数を一度に1つずつ追加できる場所cpなど、連結された変数を介してパスが追加されます。$paths = plugins world_nether mysql/hawk

tarこれらの構成ファイルをとで選択的にバックアップするにはどうすればよいcpですか?構成プロセスの性質上、両方のコマンドに追加するために同じフラグを設定する必要はありません。どちらのコマンドでも別々の引数にすることができます。

問題のコードの2つのスニペットは次のとおりです。パスを構成します。

# My first, unsuccessful attempt.
if $BKP_CFG; then
    # Tell user they are backing up config
    echo " +CONFIG $confType - NOT CURRENTLY WORKING"
    # Main directory, and everything in plugin directory only
    # Jars are not allowed to be backed up
    #paths="$paths --no-recursion * --recursion plugins$suffix --exclude *.jar"
fi

---その他のプロスタッフ----

# Set commands
if $ARCHIVE; then
    command="tar -cpv"
    if $COMPRESSION; then
        command=$command"z"
    fi
    # Paths starts with a space </protip>
    command=$command"C $SERVER_PATH -f $BACKUP_PATH/$bkpName$paths"
    prep=""
else
    prep="mkdir $BACKUP_PATH/$bkpName"
    # Make each path an absolute path. Currently, they are all relative
    for path in $paths; do
        path=$SERVER_PATH/$path
    done
    command="cp -av$paths $BACKUP_PATH/$bkpName"
fi

必要に応じて、より多くのコード/説明を提供できます。

4

2 に答える 2

2
find /actual/path ! -iname '*jar' -maxdepth 1 -exec cp \{\} /where/to/copy/ \;
find /actual/path/plugins ! -iname '*jar' -maxdepth 1 -exec cp \{\} /where/to/copy/ \;

役立つかもしれません。

于 2012-01-14T13:18:24.937 に答える
0

最終的なコード:

if $BKP_CFG; then
    # Tell user what's being backed up
    echo " +CONFIG $confType"
    # Main directory, and everything in plugin directory only
    # Jars are not allowed to be backed up
    # Find matches within the directory cd'd to earlier, strip leading ./
    paths="$paths $(find . -maxdepth 1 -type f ! -iname '*.jar' | sed -e 's/\.\///')"
    paths="$paths $(find ./plugins -type f ! -iname '*.jar' | sed -e 's/\.\///')"
fi
于 2012-01-14T23:56:56.693 に答える