Basic Backup Script
After struggling with a corrupted save yesterday, I made a simple script to make backups of my dedicated server save.
Probably this will be useful only for people that run Windows homemade servers, but here’s the script:
u/echo off
setlocal enabledelayedexpansion
rem Set origin and destination folders
set "origin=YOUR_PALWORLD_SERVER_PATH"
set "destination=YOUR_BACKUP_FOLDER_PATH"
rem Calculate the cutoff date for backups (7 days ago)
for /f "tokens=1-5 delims=/: " %%d in ("%date% %time%") do (
set /a "yy=10000+%%d, mm=100+%%e, dd=100+%%f, HH=100+%%g, MM=100+%%h"
)
set "cutoff=!yy!!mm!!dd!_!HH!!MM!"
rem Create backup folder name
set "backup_folder=!yy:~1,4!!mm:~1,2!!dd:~1,2!_!HH:~1,2!!MM:~1,2!"
rem Copy files to destination folder
xcopy "%origin%" "%destination%\%backup_folder%\" /E /I /Y > nul
rem Delete files older than 7 days (or keep the last 168 backups)
for /f "skip=168 delims=" %%F in ('dir /b /ad-h /o-d "%destination%"') do (
if "%%F" LSS "%cutoff%" (
rd /s /q "%destination%\%%F"
)
)
endlocal
Change YOUR_PALWORLD_SERVER_PATH and YOUR_BACKUP_FOLDER_PATH with your respective folder paths. I suggest backing up just the “SaveGames” folder.
Save your file in .bat format and run it once to check if it works. Then setup a task to run it in Windows Task Scheduler, I run it every hour, the script should delete files older than one week.
Be the first to comment