Home
Packages
Forums
Wiki
GitLab
Security
AUR
Download
コンテンツにスキップ
メインメニュー
メインメニュー
サイドバーに移動
非表示
案内
メインページ
目次
コミュニティに貢献
最近の出来事
おまかせ表示
特別ページ
交流
ヘルプ
貢献
最近の更新
最近の議論
新しいページ
統計
リクエスト
ArchWiki
検索
検索
表示
アカウント作成
ログイン
個人用ツール
アカウント作成
ログイン
リカバリ後のタスクのソースを表示
ページ
議論
日本語
閲覧
ソースを閲覧
履歴を表示
ツール
ツール
サイドバーに移動
非表示
操作
閲覧
ソースを閲覧
履歴を表示
全般
リンク元
関連ページの更新状況
ページ情報
表示
サイドバーに移動
非表示
←
リカバリ後のタスク
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
[[Category:システムリカバリ]] {{Related articles start}} {{Related|ファイルリカバリ}} {{Related|解像度で画像を並び替える}} {{Related articles end}} {{Note|回復または復元されたファイルへのアクセスを高速化するために、{{Pkg|shake}} ユーティリティを使用してデフラグメンテーションすることができます。}} == チェックサムで一意なファイルのみをリストする == {{Note| * ''photorec'' が元の名前を復元できるファイルのみをリストするには、''awk'' の {{ic|print}} の前に {{ic|1=if(index(A,"_") != 0)}} を追加します。すでに作成されたファイルで単独のファイル名または拡張子のみをリストする場合は、''awk'' をスタンドアロンコマンドとして使用することもできます。 * 拡張子のみをリストする場合は、''awk'' で {{ic|1=D=B;gsub(/[^.]./,"",D)}} を使用することができます。これにより、''tar.gz'' 拡張子から ''gz'' のみを表示することができます。また、ファイル名の最初のドットまでをカットする ''gsub'' の代わりに ''sub'' を使用することもできます。}} ファイルが復元されると、多くのファイルが同じ [[wikipedia:Checksum|ハッシュ値]] を持つ場合があります。重複するファイルの1つだけを含む一意のファイルのリストを作成することで、他のユーティリティを使用してファイルに関する追加情報を収集する際に、保存されたファイル名とパスを使用して高速化できます。 {{bc|<nowiki>find -type f -print0 | \ xargs -0 md5sum | \ awk '// {Count[$1]++; if( Count[$1] == 1 ){C=substr($0,index($0,"./"));A=$0;sub(/^.*\//,"",A);B=substr(A,index(A,"_")+1);HASHsum=$1; print A"|"B"|"C"|"HASHsum}}' </nowiki> }} これにより、画面に以下のパターンで結果が表示されます: '''filename|restored_filename|full_path_to_filename|check_sum''' f851733136_WindowMaker_Dockapps.pdf|WindowMaker_Dockapps.pdf|./f851733136_WindowMaker_Dockapps.pdf|272cc4fcdc8027e3b8b53318f08f3f01 === ファイル名を整理して並べる === 宛先のファイル名をより ''bash'' に使いやすくするために、特殊な記号やスペースを削除し、重複した名前を持つファイルのよりよい概要のために2番目の列でソートすることができます。重複したファイル名には、''restored_filename'' の前に {{ic|¤}} を区切り記号として加えられます。スクリプトは、上記で作成したスクリプトによって作成されたファイルを使用し、結果を ''stdout'' に出力します。 {{hc|clean_and_sort.sh|<nowiki> if [ ! -z "$1" ];then awk -F"|" '{B=$2; gsub(/\(/,"",B);gsub(/\)/,"",B); gsub(/!/,"",B); gsub(/?/,"",B); gsub(/\[/,"",B);gsub(/\]/,"",B); gsub(/{/,"",B); gsub(/}/,"",B); gsub(/&/,"",B); gsub(/=/,"",B); gsub(/\^/,"",B);gsub(/~/,"",B); gsub(" ","",B) ;gsub(/#/,"",B); gsub(/\"/,"",B);gsub(/;/,"",B); gsub(/\\/,"",B);gsub(/\//,"",B); sub(/-*/,"",B); sub(/+*/,"",B); print $1" | "B" | "$3}' "$1" | \ sort --field-separator=\| -s -d -k 2 \ awk -F'|' '{B=$2;Count[B]++;sub(/ */,"",B);if( Count[$2] == 1 ){print $1"|"B"|"$3}else{print $1"|"Count[$2]-1"¤"B"|"$3"|"$4} }' else echo 'Path to file is missing!' fi </nowiki>}} ファイル名に特殊記号が含まれている場合、特にそれらがファイル名の先頭にある場合は、クォートやバックスラッシュ {{ic|}} を使用しないと、{{ic|mv}} や {{ic|cp}} のようなコマンドで管理するのが難しくなりますが、それらをすべて削除する代わりに、[http://www.obkb.com/dcljr/charstxt.html HTML hex codes] で置き換えることができます。 == Photorec == === 配列のデータを含むファイルの作成 === この例では、[[Xdg-utils#xdg-mime|xdg-mime]] を使用して mime タイプに関する情報を収集していますが、{{ic|file --mime-type -b}} と {{ic|file -i -b}} コマンドは {{ic|xdg-mime query filetype}} コマンドと同じ出力を提供しますが、より詳細な情報を提供することもあります。このスクリプトは、'''info-mime-size-db.txt''' にファイルの追加情報を多数収集します。スクリプトを ''photorec'' で使用した宛先ディレクトリに配置し、宛先ディレクトリ内のユニークなチェックサムのリストからのファイルへのパスを使用して実行します。例:{{ic|<nowiki>awk -F" | " '{system("start-collect-file-info.sh "$3" "$1" "$2)}'</nowiki> ''file_list-unique_checksums''}} {{hc|start-collect-file-info.sh|<nowiki>#!/bin/bash if [ ! -z "$1" ] && [ ! -z "$2" ] && [ ! -z "$3" ]; then if [ -f "$1" ]; then echo "$1" echo "$(file "$1" -F"|" )'|'$(xdg-mime query filetype "$1")'|'$(du -h "$1" |awk '{print $1}' )|$2|$3" >> info-mime-size-db.txt else echo The « "$1" » is not a valid file name. fi fi</nowiki>}} このスクリプトは、'''path to file/file name | info about the file | mime type | size | filename | restored_filename''' のパターンでファイルを作成します。以下に例を示します:{{ic|<nowiki>./recup_dir.1/f872690288_image.jpg|JPEG image data, JFIF standard 1.01|image/jpeg|24K|f872690288_image.jpg|image.jpg</nowiki>}} === リカバリ後のタスク === このスクリプトは、'''path to file/file name | info about the file | mime type | size | filename | restored_filename''' のパターンでファイルを作成します。以下に例を示します:{{ic|<nowiki>./recup_dir.1/f872690288_image.jpg|JPEG image data, JFIF standard 1.01|image/jpeg|24K|f872690288_image.jpg|image.jpg</nowiki>}} {{Warning| * Remove the {{ic|echo}} command in front of the {{ic|cp}} and {{ic|mkdir}} otherwise the script will only show what is going to to be done without restoring anything to a destination, do a dry run. To use {{ic|echo}} command is good for verify that settings for filenames and destinations looks correctly. * Those scripts are only examples for restoration of files from folders created by ''photorec'', be careful!}} ==== Head of the script ==== Here is a simple check if the {{ic|info-mime-size-db.txt}} exists in the current directory to prevent possible errors with rest of the script. {{bc|#!/bin/bash if [ -f info-mime-size-db.txt ]; then echo The file info-mime-size-db.txt exists continuing... ; else echo Error!! the info-mime-size-db.txt file cannot be found;exit 1; fi }} ==== Start variables ==== {{bc|1=CountAll="0" CountToLimit="0" BaseSubDirName="MyRestoredFiles" Destination="$HOME/NameOfBaseFolder/${BaseSubDirName}-MoreDetailsInFolderName/" NewDirNumber="0" CountToLimit="0"}} ==== Populate an array ==== {{Warning|Arrays become populated by reading data from a {{ic|info-mime-size-db.txt}} file. Otherwise the script will not work correctly!}} ===== With a while loop ===== Here will be a short examples about how to speed up population of the array from a file with patterns by using [https://tldp.org/LDP/abs/html/string-manipulation.html bash standard expressions] instead of ''awk'', ''grep'' and ''sed''. The {{ic|ArrayOfFiles}} array will contain full path to the file and the {{ic|ArrayOfsorted}} will contain original names restored by ''photorec'' but without random generated part. {{bc|<nowiki> WhileArray=0; while read i; do if [[ "$i" =~ "gif" ]]||[[ "$i" =~ "jpeg" ]];then ArrayOfFiles[WhileArray]=${i/'|'*/} ArrayOfsorted[WhileArray]=${i/[^*|]*|/} WhileArray=$((WhileArray+1)); fi; done < info-mime-size-db.txt echo done, the array is full </nowiki>}} ==== Loops for restoration ==== This is a finale part of a script that manages restoration of files. When limit of files in a destination sub-directory reached then it creates and new one numbered sub-directory in the destination folder and continuing to copy files there. {{bc|<nowiki>SizeOfArray=${#ArrayOfFiles[@]} while [ "${SizeOfArray}" != "${CountAll}" ]; do IfExist="${Destination}${BaseSubDirName}${NewDirNumber}" if [ ! -d "${IfExist}" ]; then echo mkdir -v "${IfExist}" -p;fi CountToLimit=$((CountToLimit+1 )) FileName=${ArrayOfsorted[CountAll]} if [ $CountToLimit -gt 25 ]; then CountToLimit="0" NewDirNumber=$((NewDirNumber+1)) fi; NewDestination="$IfExist" echo cp -fv "$PWD/${ArrayOfFiles[CountAll]}" "${IfExist}${FileName}" CountAll=$((CountAll+1)) done</nowiki>}} {{Note|In order to add more specific details about files in their names or names of the destination directories you will need to gather information about them with external programs, e.g. for image resolution: {{Pkg|feh}} {{ic|<nowiki>feh -l "${ArrayOfFiles[$CountAll]}" | tail -1 | awk '{print $3"x"$4}'</nowiki>}}, {{Pkg|imagemagick}} {{ic|<nowiki>identify ${ArrayOfFiles[$CountAll]} | awk '{print $3}'</nowiki>}}. }} == Enough if files are few == If it is not so many files with the same extension then it will be enough to use something like {{ic|find -name *.xcf -exec copy "{}" $HOME/Desktop \;}} to avoid the ''overload'' of a destination folder you can calculate how many files are found {{ic|<nowiki>find -type f -name *xcf | wc -l</nowiki>}}. {{Note|The photorec utility stores up to 500 recovered files in a single folder.}}
このページで使用されているテンプレート:
テンプレート:Bc
(
ソースを閲覧
)
テンプレート:Hc
(
ソースを閲覧
)
テンプレート:Ic
(
ソースを閲覧
)
テンプレート:META Related articles start
(
ソースを閲覧
)
テンプレート:Note
(
ソースを閲覧
)
テンプレート:Pkg
(
ソースを閲覧
)
テンプレート:Related
(
ソースを閲覧
)
テンプレート:Related articles end
(
ソースを閲覧
)
テンプレート:Related articles start
(
ソースを閲覧
)
テンプレート:Warning
(
ソースを閲覧
)
リカバリ後のタスク
に戻る。
検索
検索
リカバリ後のタスクのソースを表示
話題を追加