Created
September 16, 2013 08:33
-
-
Save Illvili/6578017 to your computer and use it in GitHub Desktop.
ThinkPHP log archiver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
log_path="/home/www/[APP_NAME]/App/Runtime/Logs" | |
archive_path="/home/logs_archiver"; | |
# some command | |
list_all_pattern="ls $log_path/13_*.log -1 | xargs -n 1 -I %_ basename %_ .log" | |
# archive files | |
Archive_Files () { | |
file_count=`ls -1 ${log_path}/*$1.log 2>/dev/null | wc -l` | |
echo "There is ${file_count} files to archive" | |
if [ $file_count != 0 ]; then | |
echo "Archiving..." | |
tar -zcvf $archive_path/$1.tar.gz ${log_path}/*$1.log >/dev/null | |
echo "Removing..." | |
rm -rf ${log_path}/*$1* >/dev/null | |
fi | |
echo "Done"; | |
} | |
if [ "$1" == "" ]; then | |
echo "USAGE: $0 DATE_TO_ARCHIVE" | |
echo " OR: $0 -l|--list" | |
echo " OR: $0 -a|--all" | |
elif [ "$1" == "-l" ] || [ "$1" == "--list" ]; then | |
eval $list_all_pattern | |
elif [ "$1" == "-a" ] || [ "$1" == "--all" ]; then | |
patterns=`eval $list_all_pattern | head -n -1` | |
for pattern in $patterns | |
do | |
echo "Archiving $pattern..." | |
Archive_Files $pattern | |
done | |
echo "" | |
echo "All Done"; | |
else | |
Archive_Files $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment