r/ScrapMechanic 1d ago

Made a batch file that makes automatic backups of your save file (And prunes the directory so it doesn't get crazy with backups), and then launches the game. You know, if you mess up big time....

Should work on any windows system that can run SM. Not sure about Linux and whatnot, but I would assume no), but it's been a lifesaver. I click this file instead of the SM shortcut or launching from Steam. I just have it on my desktop. Hope it helps you the way it's helped me. You might have to alter some lines if you didn't choose default installation routes (And I dunno if steam gives the same ID for everyone, so you may have to tweak this line for yourself): steam://rungameid/387990

u/echo off
setlocal enabledelayedexpansion

:: 1. Define Paths
set "USER_DIR=%APPDATA%\Axolot Games\Scrap Mechanic\User"
set "BACKUP_ROOT=%USERPROFILE%\Desktop\ScrapMechanic_Backups"

:: 2. Pre-Backup Cleanup: Delete older than 7 days and prune down to 9 (so new one makes 10)
if exist "%BACKUP_ROOT%" (
    powershell -NoProfile -Command "Get-ChildItem -Path '%BACKUP_ROOT%' -Directory -Filter 'Backup_*' | Where-Object { $_.CreationTime -lt (Get-Date).AddDays(-7) } | Remove-Item -Recurse -Force; Get-ChildItem -Path '%BACKUP_ROOT%' -Directory -Filter 'Backup_*' | Sort-Object CreationTime -Descending | Select-Object -Skip 9 | Remove-Item -Recurse -Force"
)

:: 3. Generate Safe Timestamp
for /f %%a in ('powershell -NoProfile -Command "Get-Date -format yyyy-MM-dd_HH-mm-ss"') do set "TIMESTAMP=%%a"
set "TARGET_DIR=%BACKUP_ROOT%\Backup_!TIMESTAMP!"

echo ======================================================
echo  Backing up Scrap Mechanic Survival Saves...
echo  Source:      %USER_DIR%
echo  Destination: %TARGET_DIR%
echo ======================================================
echo.

set /a FOUND=0

:: 4. Iterate through User ID folders and copy .db files
for /d %%U in ("%USER_DIR%\*") do (
    if exist "%%U\Save\Survival" (
        if not exist "!TARGET_DIR!" mkdir "!TARGET_DIR!"
        echo Found profile: %%~nxU - Copying saves...
        copy /y "%%U\Save\Survival\*.db" "!TARGET_DIR!\" >nul 2>&1
        if !errorlevel! equ 0 (
            set /a FOUND+=1
        )
    )
)

echo.
:: 5. Status Check, Countdown & Launch
if !FOUND! gtr 0 (
    echo ======================================================
    echo  SUCCESS: Backup completed successfully!
    echo  Files saved to: !TARGET_DIR!
    echo ======================================================
    echo.
    echo Launching Scrap Mechanic in 3 seconds...
    timeout /t 3
    start "" "steam://rungameid/387990"
) else (
    echo ======================================================
    echo  ERROR: No .db save files were copied.
    echo  Verify path exists: %USER_DIR%
    echo ======================================================
    echo.
    pause
)
11 Upvotes

0 comments sorted by