よく忘れるので備忘録しておきます。
溜まった過去ログの古く不要なのを削除するのに使ってます。
[ コマンド例 ]
180日以上前のファイルを削除
find /parentdirectoryname/directoryname -mtime +180 -exec rm -f {} \;
詳しくはここに書いてくださってます : https://qiita.com/narumi_/items/9ea27362a1eb502e2dbc
Semakin di depan

よく忘れるので備忘録しておきます。
溜まった過去ログの古く不要なのを削除するのに使ってます。
[ コマンド例 ]
180日以上前のファイルを削除
find /parentdirectoryname/directoryname -mtime +180 -exec rm -f {} \;
詳しくはここに書いてくださってます : https://qiita.com/narumi_/items/9ea27362a1eb502e2dbc
Windows でディレクトリのサイズ合計を見せてくれるアプリがありますが、Linuxで同様のことがわかるシェルスクリプトを作ってます。
容量的に厳しくなってきたサーバーのファイル整理、無駄に溜まってる過去のログのチェックなどに使えると思います。
調べたいディレクトリをカレントにして、コマンドを実行。
shファイルのフルパスを指定する必要あるので、alias で設定しておけば便利と思います。
[ スクリプト ]
#!/bin/sh
#
# target directory file size summary list
#
tgt=`pwd`
echo ${tgt}
dirs=${tgt}/*
# loop current directory #
for filepath in ${dirs}; do
# if filename belongs directory #
if [ -d ${filepath} ]; then
# if excluded dir, do nothing.
if [ $# -eq 2 ] && [ $1 = "E" ] && [ $2 = ${filepath} ] ; then
echo ${filepath}" ignored"
else
du -sh ${filepath}
fi
# if param count equals 1 and "C" #
# print a file count #
if [ $# -eq 1 ]; then
if [ $1 = "C" ]; then
find ${filepath} | wc -l
echo "---------------------------------"
fi
fi
fi
done
[ 利用例 ]
引数なし
[root@???? opt]# /scriptdir/scriptname.sh /opt 30M /opt/firebird 190M /opt/google 382M /opt/openoffice4 700M /opt/saw17 392M /opt/sqlanywhere16
$1 : C
ファイル数も出力
[root@???? opt]# scriptdir/scriptname.sh C /opt 30M /opt/firebird 256 --------------------------------- 190M /opt/google 101 --------------------------------- 382M /opt/openoffice4 4275 --------------------------------- 700M /opt/saw17 1913 --------------------------------- 392M /opt/sqlanywhere16 2810 ---------------------------------
$1 : E
$2 : 対象からはずすディレクトリ
[root@???? opt]# /scriptdir/scriptname.sh E /opt/google /opt 30M /opt/firebird /opt/google ignored 382M /opt/openoffice4 700M /opt/saw17 392M /opt/sqlanywhere16
|
|

mysql のコマンドで、テーブルの定義や細かいステータスは見れますが、ふと収容先の全データベースのサイズを見る必要があったので、自作してます。
名前は、コマンド用なので短くして、引数なしにしてます。
[ DDL ]
CREATE DEFINER=`root`@`localhost` PROCEDURE `dbsize`()
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT '簡単データベースサイズ'
BEGIN
SELECT
table_schema,
sum(data_length) /1024/1024 + sum(index_length) /1024/1024 AS total_mb,
sum(data_length) /1024/1024 AS data_mb,
sum(index_length) /1024/1024 AS index_mb
FROM
information_schema.tables
GROUP BY
table_schema
ORDER BY
sum(data_length + index_length) DESC;
END
[ 利用例 ]
mysql> call dbsize; +--------------------+---------------+---------------+---------------+ | table_schema | total_mb | data_mb | index_mb | +--------------------+---------------+---------------+---------------+ | ?????????? | 4028.40940857 | 2589.96604919 | 1438.44335938 | | ?????????? | 3389.75976753 | 2149.07226753 | 1240.68750000 | | ?????????? | 1720.67187500 | 812.59375000 | 908.07812500 | | mysql | 11.26994324 | 10.99552917 | 0.27441406 | | ?????? | 3.45312500 | 2.07812500 | 1.37500000 | | information_schema | 0.15625000 | 0.15625000 | 0.00000000 | | sys | 0.01562500 | 0.01562500 | 0.00000000 | | performance_schema | 0.00000000 | 0.00000000 | 0.00000000 | +--------------------+---------------+---------------+---------------+ 19 rows in set (0.27 sec) Query OK, 0 rows affected (0.27 sec)
コメントを投稿するにはログインしてください。