Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: This file will make sure only the most recent 5 backups are kept
- :: When making backup ups in the "minutes" like I work heavy in mine so
- :: i have it set to every 15min, this ofcourse fills up the backup folder
- :: so I wrote this to make sure only 5 are there.
- :: as an extra, I have only the recent file of the day to send to dropbox
- @echo off
- setlocal EnableDelayedExpansion
- :: Set the backup directory to the correct path
- set "BACKUP_DIR=C:\Minecraft Server\WorldBackup"
- set "DROPBOX_DIR=%USERPROFILE%\Dropbox\Minecraft"
- :: Navigate to the backup directory
- cd /d "%BACKUP_DIR%"
- :: Create a temporary file list in the temp directory
- set "temp_file=%temp%\%~n0.tmp"
- dir /b /a-d /o-d "* (Full).7z" > "!temp_file!"
- :: Count the total number of backup files
- set /a "file_count=0"
- for /f "tokens=*" %%a in ('type "!temp_file!"') do set /a file_count+=1
- :: Only run deletion if there are more than 5 backup files
- if !file_count! GTR 5 (
- set /a "count=0"
- :: Process each file, deleting those beyond the fifth
- for /f "tokens=*" %%f in ('type "!temp_file!"') do (
- set /a count+=1
- if !count! GTR 5 (
- echo Deleting: %%f
- del "%%f"
- )
- )
- echo Backup cleanup is complete.
- ) else (
- echo "Not enough files to start cleanup. Only !file_count! file(s) out of 5 required found."
- )
- :: Identify the most recent file (which is the first one in the list due to the order by date descending)
- set "most_recent_file="
- for /f "tokens=*" %%g in ('type "!temp_file!"') do (
- if not defined most_recent_file set "most_recent_file=%%g"
- )
- :: Check if the Dropbox directory exists and create if not
- if not exist "!DROPBOX_DIR!" mkdir "!DROPBOX_DIR!"
- :: Copy the most recent file to the Dropbox directory
- if defined most_recent_file (
- echo Copying the most recent file: !most_recent_file! to Dropbox...
- copy "!BACKUP_DIR!\!most_recent_file!" "!DROPBOX_DIR!"
- echo Most recent file copied successfully.
- ) else (
- echo No files were found to copy.
- )
- :: Clean up the temporary file
- del "!temp_file!"
- endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement