0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

共用ファイルサーバが容量不足でつらい時にやるやつ

Posted at

ファイルサーバの容量が足りないけどディスクの増設が見込めない時の覚書です。
基本的には目視で削除または圧縮をします。

まず、何度もファイルサーバに負荷を掛けると迷惑になるので、とりあえず一覧を csv に吐きます。

ls -force -recurse -file \\xxx.xxx.xxx.xxx\share `
    | select lastwritetime,extension,length,Name,Directory,FullName `
    | convertto-csv -nti `
    | out-file share.csv

とりあえずこの状態でエクセルで開くと素人でも要らないファイルを探せるようになります。

とはいえ、PowerShell を使いたいので、引き続きサイズの大きい項目を探します。

import-csv share.csv | ? extension -ne .zip | ? length -gt 1gb
import-csv share.csv | ? extension -ne .zip | ? length -gt 500mb
import-csv share.csv | ? extension -ne .zip | ? length -gt 100mb

見つかった項目を削除または圧縮していきます。
テキスト系は圧縮が効きやすく、1/50 程度になることが期待できます。
圧縮前のファイルは忘れずに削除しておきます。

次に作業履歴系のフォルダを圧縮します。
何らかの作業履歴系のフォルダは、「いつか参照するかもしれない」などの理由で長年保管されている場合が多いです。
また、「削除に慎重な人」の反感を買うので、基本的に削除ができません。
これらのフォルダ群は、大抵 FullNameyyyymmdd にマッチします。

import-csv share.csv | ? { $_.FullName -match "\d{8}" }

# 履歴が溜まっているフォルダを指定して
ls -directory \\xxx.xxx.xxx.xxx\share\hoge\fuga\history `
    | % {
        $z = $_.fullname + ".zip"
        compress-archive -dest $z -path $_.fullname # パスが長すぎると失敗する
        if ($? -and (Test-Path $z)) { rm -force -recurse $_.FullName }
    }

残念なファイルサーバには歴史が詰まっていることが多く、割と効果があります。
また、ファイル数が多い場合は、実際のデータ量よりもディスクを圧迫するので、フォルダ単位で圧縮してファイル数を減らすと効果が高いです。
副次的な効果として、ファイル数が減ると csv の見通しが良くなってファイルの整理が捗ります。

最後にLastWriteTimeを見て、部署で一番古株の人よりも古いファイルの削除を試みます。

$old = (date).addyears(-10)
import-csv share.csv | ? { [datetime]$_.lastwritetime -lt $old } | % { rm -force $_.fullname }

後で大惨事にならないことを祈りながら実行しましょう。
共用ファイルサーバの寿命が伸びたら良いですね。

このような問題が起こる原因は杜撰なデータ管理と削除ルールの未整備(と年々ファイルサイズが大きくなる問題)ですが、データの管理者とルールの整備責任者は特に困っていないことが多くて救えないですね。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?