以下のコマンドを使えば「/home/hoge/」(サブフォルダも含む)中の作成日は一ヶ月前のファイルを消すことができます
更に接尾詞は「.log」のファイルを絞りたい時
以下のコマンドを使えば「/home/hoge/」(サブフォルダも含む)中の作成日は一ヶ月前のファイルを消すことができます
find /home/hoge/ -type f -mtime +30 -exec rm -f {} \; |
更に接尾詞は「.log」のファイルを絞りたい時
find /home/hoge/ -name "*.log" -type f -mtime +30 -exec rm -f {} \; |
たまに特定な条件に一致するデータを削除したい時があります。
SolrのAPIを使えば実現できます。xml形式とjson形式をそれぞれ紹介します。
例:「title」というフィルドが存在します。「title」の中文字列「プレミアム」が存在しているドキュメントを全部削除
curl 'http://localhost:8983/solr/コア名を入れて/update?commit=true&stream.body=<delete><query>title:*プレミアム*</query></delete>' |
形式2、json形式で削除
例:「category」(カテゴリ)と「update_at」(更新日)というフィルドが存在します。更新日は2018年12月13日前、かつカテゴリが「fasion」のドキュメントを削除
curl -H 'Content-Type: application/json' \'http://localhost:8983/solr/コア名を入れて/update?commit=true' \-d '{ "delete": { "query": "category:fasion AND update_at:[* TO 2018-12-13T00:00:00]" }}' |
時々テーブルのデータが蓄積しすぎでディスク容量を圧迫されることがあります。その時以下のコマンドを使えばテーブル毎の容量、行数など情報をみることができます。
SELECT table_name, engine, table_rows, (data_length+index_length)/1024/1024/1024 as allGB, (data_length)/1024/1024/1024 as dataGB, (index_length)/1024/1024/1024 as indexGBFROM information_schema.tablesWHERE table_schema=database()ORDER BY (data_length+index_length) DESC;+--------------------+--------+------------+-----------------+-----------------+----------------+| TABLE_NAME | ENGINE | TABLE_ROWS | allGB | dataGB | indexGB |+--------------------+--------+------------+-----------------+-----------------+----------------+| user | InnoDB | 33543611 | 17.791976928711 | 16.137695312500 | 1.654281616211 || product | InnoDB | 43979 | 0.893157958984 | 0.893157958984 | 0.000000000000 || comment | InnoDB | 0 | 0.000244140625 | 0.000015258789 | 0.000228881836 || category | InnoDB | 0 | 0.000244140625 | 0.000015258789 | 0.000228881836 |+--------------------+--------+------------+-----------------+-----------------+----------------+ |
先程テーブル単位のデータ容量を確認できましたが、以下のクエリーを使えばデータベース単位での容量も確認できます。
SELECT table_schema, sum(data_length) /1024/1024/1024 AS GBFROM information_schema.tables GROUP BY table_schemaORDER BY sum(data_length+index_length) DESC;+---------------------+-----------------+| table_schema | GB |+---------------------+-----------------+| bbs | 81.270685018040 || user | 13.613167230971 || product | 1.102905860171 || test | 0.629666061141 || log | 0.017431590706 || auth | 0.003235515207 || information_schema | 0.000000000000 |+---------------------+-----------------+ |