LOGS - Script to clean the partitions of the file server and to effect the backup of the logs by FTP
From wiki.morphey.org
This script that I have done, serves to:
1 - to effect the backup of the logses of system through FTP; 2 - to cancel the old whole logses; 3 - to free, in general, the space on the disks.
If the script is editted, he is able' to change the host of the FTP, user and password.
cleaning_server.sh
#!/bin/bash echo echo echo "********* Cleaning Server for cPanel **********" echo echo "This script effects the cleaning of the file server to free the partitions" echo "and backup all to a FTP server." echo echo "For info: morphey@morphey.org or christian@serverplan.com" echo echo # Settings FTP server FTP_SERVER="your_ip_server" FTP_USER="your_user" FTP_PASS="your_pass" # DO NOT EDIT FROM HERE FILE_BACKUP="$(hostname).$(date +"%d-%m-%Y").tar" TMPDIR="/home/" echo "Tar File: $TMPDIR$FILE_BACKUP ..." rm -f $TMPDIR$FILE_BACKUP tar -cf $TMPDIR$FILE_BACKUP /var/log/cron* /var/log/exim_mainlog* /var/log/exim_paniclog* /var/log/exim_rejectlog* /var/log/messages* /var/log/secure* /usr/local/apache/logs echo "..ok. Gzip file $TMPDIR$FILE_BACKUP ..." gzip $TMPDIR$FILE_BACKUP echo "..ok." echo "Putting file on FTP server $FTP_SERVER ..." DIRCURRENT=`pwd` cd $TMPDIR ftp -n $FTP_SERVER <<End-of-Session user $FTP_USER "$FTP_PASS" binary bell pwd put "$FILE_BACKUP.gz" ls bye End-of-Session shift rm -rf $TMPDIR$FILE_BACKUP.gz cd $DIRCURRENT echo "..ok, I have put a file on FTP server." echo "Removing obsolete old's files..." LOGS_FILES_REMOVE="cron exim_mainlog exim_paniclog exim_rejectlog messages secure" for i in $LOGS_FILES_REMOVE do echo "remove /var/log/$i.*" rm -f /var/log/$i.* done echo "Stopping apache, removing logs and restart it..." service httpd stop sleep 5 killall -9 httpd rm -f /usr/local/apache/logs/* service httpd startssl echo "Removing oboslete old's file of cPanel-backup..." rm -rf /home/cpbackuptmp/* rm -rf /home/cprestore/* rm -rf /home/backup/cpbackup/* echo "..ok, I have ended :)" echo
