1

I have searched everywhere but cannot find a solution. Im unsure what is going on here but I desperately need some help in regards to this issue, Im running a batch file (Script for a game Server monitor/crash restarter).

I decided to add a Log file Archival snippet which creates a folder named with the date and a subfolder named with the time then robocopy /mov the logs from the main folder to the archive folder that gets created each time the game server restarts (3hrs).

I tested the snippet on its own and in the rest of the batch script and it works fine, I also confirmed it to work in the task scheduler that the script is run from at server startup, however I notice that it may work once then the next time it needs to create the new directory and move the logs to the new date\time it gets moved to the previous date\time folder and doesnt make the new time directory, this is an example I use,

@echo off
set PROFILE=C:\GameServers\Server1\Profile
set SVR_LOGS=C:\GameServers\Server1\Profile\Logs\Archived_Logs
set ARC_FOLDER=%date:~10,4%_%date:~7,2%_%date:~4,2%\%time:~0,2%-%time:~3,2%-%time:~6,2%

echo Archiving Logs...
timeout 3 >nul
cd %SVR_LOGS%
mkdir %ARC_FOLDER%
robocopy *.log %PROFILE% %SVR_LOGS%\%ARC_FOLDER% /mov
robocopy *.adm %PROFILE% %SVR_LOGS%\%ARC_FOLDER% /mov
robocopy *.rpt %PROFILE% %SVR_LOGS%\%ARC_FOLDER% /mov
robocopy *.mdmp %PROFILE% %SVR_LOGS%\%ARC_FOLDER% /mov
cls
echo Log Archive Complete!...
timeout 3 >nul
cls

I have also tried other methods of doing this but it seems to do the same thing no matter which way I have it, game server host is a vm running server 2016 on dedicated server with server 2019 (Long story as to why that is dont worry, for short its for test purposes)

Boss-Prime
  • 11
  • 2
  • Check output from `move /?`. All your `move` commands are wrong syntax. – JosefZ Dec 27 '19 at 22:09
  • I only realized this, has been a long night, it was another method I used but without the /mov ,.. it was meant to be robocopy not move command,when I made this post it was off the top of my head,very late evening, I removed the move command and replaced it to better reflect my question, thanks btw. – Boss-Prime Dec 28 '19 at 05:28

1 Answers1

0

You should use this:

@echo off
set PROFILE="C:\GameServers\Server1\Profile" 
set SVR_LOGS="C:\GameServers\Server1\Profile\Logs\Archived_Logs"
 set ARC_FOLDER="%date:~10,4%_%date:~7,2%_%date:~4,2%\%time:~0,2%-%time:~3,2%-%time:~6,2%" 
echo Archiving Logs... 
timeout 3 >nul 
Pushd %SVR_LOGS% 
mkdir %ARC_FOLDER% 
Move *.log %PROFILE% 
Move *.log %SVR_LOGS%\%ARC_FOLDER% 
Move *.adm %PROFILE% 
Move *.adm %SVR_LOGS%\%ARC_FOLDER% 
Move *.rpt %PROFILE%
Move *.rot %SVR_LOGS%\%ARC_FOLDER% 
Move *.mdmp %PROFILE% 
Move *.mdmp %SVR_LOGS%\%ARC_FOLDER%
cls 
echo Log Archive Complete!... 
timeout 3 >nul 
cls
Wasif
  • 321
  • 2
  • 8
  • I have tried numerous similar methods to this but still I get every log being moved to the first folder that was made when the script was started, the script is not making new directories based on the date and time the server restarts/crashes.This script is started and runs continuously in a loop and archives the log files each time the servers restarts/crashes so in one 24hr period I should have a folder named with the date and inside that folder I should have sub directories folders named with the times for every restart/crash containing the log files for each. – Boss-Prime Dec 30 '19 at 03:29
  • I may have found an answer to this issue, I have it working non stop now so far, My changes were 1, adding setlocal enableextensions 2, using normal %date% %time% and set to remove the forward slash 3, moving the set date etc to the actual code snippet and not having it at the top. Will test out further then may post it as an answer to my own question. – Boss-Prime Jan 06 '20 at 04:20