SA-MP Server Log Rotation
#21

Looks Sweet. Now to try it
Reply
#22

Allright, so I was searching for a automatic server restarter, done some research in batch programming lol, first KingJ came up with this:

Code:
:SERVERSTART
samp-server
GOTO SERVERSTART
This will restart the server if you EXIT it, but then I thought what if someone puts 'gamemode0 asd 1' but asd.amx isn't in the gamemodes directory.. so I tested it and the server restarted a thousand time and filled up the server_log.txt really fast :X

So uhm yeah I did some more research on ******, find some time/date functions & used KingJ rotation script, modified it and came up with this:

pawn Code:
@ECHO OFF&SETLOCAL

FOR /f "tokens=1-4 delims=/-. " %%G IN ('date /t') DO (call :S_FIXDATE %%G %%H %%I %%J)
 
:S_FIXDATE (
  if "%1:~0,1%" GTR "9" shift
  FOR /f "skip=1 tokens=2-4 delims=(-)" %%G IN ('echo.^|date') DO (set %%G=%1&set %%H=%2&set %%I=%3)
)

FOR /f "tokens=*" %%G IN ('time/t') DO set _time=%%G
SET _time=%_time:~0,2%-%_time:~3,2%
ENDLOCAL&SET _time=%_time%

SET delay=20 // 1 = 1 second - set the delay of a server restart after a rcon exit
SET ServerDirectory="C:\Path\To\Your\Server" // set this to the path to your server
SET title=My First SA-MP Server :) // set the title of your server

TITLE %title%

ECHO -
ECHO Server Restarter & Log Rotation - By Sneaky
ECHO -

:SERVER_FIRST_START (
  samp-server
  GOTO SERVER_START
)

:SERVER_START (
  ECHO Restarting server with a delay of %delay% seconds...
  ECHO Renaming log file to log_%dd%-%mm%-%yy%-%_time%.txt...
  RENAME %ServerDirectory%\server_log.txt log_%dd%-%mm%-%yy%-%_time%.txt
  ECHO Moving log to logs folder...
  MOVE %ServerDirectory%\log_%dd%-%mm%-%yy%-%_time%.txt %ServerDirectory%\logs
  ECHO Succes!
  PING -n %delay% 127.0.0.1 >nul
  samp-server
  GOTO SERVER_START
)
This will restart the server ~20 seconds after rcon exit is used and creates a log file with date/time in a folder called 'logs' in your server directory.. I tested it and it works all fine, dont know if this is the best way or if it's usefull for anyone but yeah anyways..

Setup:

1. Copy code above
2. Open notepad > paste it in
3. Change SET ServerDirectory="C:\Path\To\Your\Server"
4. Optional you can change the delay time and title of the server
5. Save as startserver.bat
6. Start up startserver.bat instead of samp-server.exe
7. Dont forget to create a folder called 'logs' inside your server directory!
Reply
#23

Sneaky your code uses the time and date from when the .bat file was first run, so the logs keep getting over written on every restart.
Reply
#24

You sure? Cause I tested it and it uses the current time and not the time when the .bat file was first run everytime.. ;X
Reply
#25

Ok so I've skimmed through the topic.

And I've read things like the server recreates a log file automatically and that it doesn't.

If it doesn't, can't you just touch "server_log.txt"? And you got your problem solved, no reason for the server to restart.
BTW I always tarred my logs to reduce filesize and then transferred them to an apache server (Or FTP Folder in some other peoples cases) so I could download them from my main computer. If anyone wants that script just reply, it's quite simple. (Just tars the file to my webserver and then rm's the server_log.txt)
Reply
#26

For our versus server it seems anytime I try and just jump in the server my search key will not work, everytime I restart the server before going in game it works. Does anyone know if there is a mod or script so that after the server has people in it then goes empty it automaticly restarts?
Thanks guys
Reply
#27

I can. Muhahaha.
Reply
#28

Confusing.... But cool !
Greetz,
Machine.
Reply
#29

I made an edit, with this improvement, you dont need to specify the path, just remember to put it in your server folder

Code:
@echo off

Set ServerDirectory=%CD%
set ServerName="samp-server.exe"

for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c

if not exist %ServerDirectory%\log mkdir %ServerDirectory%\log

echo Daily log rotator for SA-MP Servers by KingJ
echo Will rename the current log file to today's date (%DATE%)
echo and place it in the log folder.
echo.
echo Path to use:
echo %CD%
echo.
echo Ensure the server is not running.
echo.
echo This makes the server logs easier to manage
echo.
echo Stopping server...
taskkill /f /im "%ServerName%"
echo Renaming log file to server_log_%XDate%.txt
rename %ServerDirectory%\server_log.txt server_log_%XDate%.txt
echo Moving log to log folder...
move %ServerDirectory%\server_log_%XDate%.txt %ServerDirectory%\log
echo Starting Server...
start %ServerDirectory%\%ServerName%
echo.
echo Log rotation complete
Reply
#30

x-serverz has had this for ages as i said to tommis once were's my log file's, as when ever you reset your server it auto puts log in a folder and then makes a new one, but before he told me how it worked i wasn't sure were my log files were going lol then i opened me log folder it had about 2000 files lol.
Reply
#31

XD, I should make a .bat that sends my log automatically go into my recycling bin
Reply
#32

I have configures the conf file, but now what I need to do ?

Many thanks for your help
Reply
#33

Yep i agree!
Reply
#34

Above two posters - wait what?
Reply
#35

Awesomeness double post, I was sorting through my NAS when I came across this. Points given to those who know what this is:

Code:
$directory = "C:\path\to\sa-mp\server\"
$serverlog = "server_log.txt"


if((Test-Path -path "$directory\logs\") -ne $True)
{
	New-Item "$directory\logs\" -type directory
	echo "A new log directory has been created."
}


$timestamp = (date -uFormat %s)
$thedate  = (date)

cat "$directory\$serverlog" | out-File -encoding ascii "$directory\logs\server.$timestamp.txt"
echo "Refreshed at $thedate" | out-File -encoding ascii "$directory\$serverlog"
Reply
#36

Is there a way to delete the server_log when the server closes? Or to disable the log feature?
I kinda hate the server_log.txt beeing put in my main server folder, and i'd like to use my own logging feature? Is it possible to disable it?
Reply
#37

OOOOOOOOOOH CRAP! my log is 1.91 MB ...sigh... oh well il delete it . But usefull .
Reply
#38

Quote:
Originally Posted by kaisersouse
View Post
NotE:

if you remove server_log.txt while the server is running...it will not automatcially recreate it.

You must stop the server
run the log rotation scrpt
restart the server
Use this to empty / blank the old log instead of removing it so the server will keep on logging:

Step 1: Copy the log contents to a new file with "cat server_log > otherlog/today.txt"
Step 2: Overwrite the server_log stream with null data by using "echo > server_log.txt" - this will blank the log file and server will continue appending new data to it.

This is tested and works fine on linux.
Reply
#39

Quote:
Originally Posted by Westingham
View Post
For those admin who use this log rotation .bat, how do you make sure all data is saved before the server goes down?
good job on a 10 month old bump ..

Your stuff doesnt get lost.. just make it autosave with a timer function in ur script .......
Reply
#40

where to put the logrotate.sh ?

thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)