Advertisement
Ra7eN

Minecraft Backup Upkeep with Dropbox

Apr 14th, 2024
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.10 KB | Gaming | 0 0
  1. :: This file will make sure only the most recent 5 backups are kept
  2. :: When making backup ups in the "minutes" like I work heavy in mine so
  3. :: i have it set to every 15min, this ofcourse fills up the backup folder
  4. :: so I wrote this to make sure only 5 are there.
  5. :: as an extra, I have only the recent file of the day to send to dropbox
  6.  
  7.  
  8. @echo off
  9. setlocal EnableDelayedExpansion
  10.  
  11. :: Set the backup directory to the correct path
  12. set "BACKUP_DIR=C:\Minecraft Server\WorldBackup"
  13. set "DROPBOX_DIR=%USERPROFILE%\Dropbox\Minecraft"
  14.  
  15. :: Navigate to the backup directory
  16. cd /d "%BACKUP_DIR%"
  17.  
  18. :: Create a temporary file list in the temp directory
  19. set "temp_file=%temp%\%~n0.tmp"
  20. dir /b /a-d /o-d "* (Full).7z" > "!temp_file!"
  21.  
  22. :: Count the total number of backup files
  23. set /a "file_count=0"
  24. for /f "tokens=*" %%a in ('type "!temp_file!"') do set /a file_count+=1
  25.  
  26. :: Only run deletion if there are more than 5 backup files
  27. if !file_count! GTR 5 (
  28.     set /a "count=0"
  29.    
  30.     :: Process each file, deleting those beyond the fifth
  31.     for /f "tokens=*" %%f in ('type "!temp_file!"') do (
  32.         set /a count+=1
  33.         if !count! GTR 5 (
  34.             echo Deleting: %%f
  35.             del "%%f"
  36.         )
  37.     )
  38.     echo Backup cleanup is complete.
  39. ) else (
  40.     echo "Not enough files to start cleanup. Only !file_count! file(s) out of 5 required found."
  41. )
  42.  
  43. :: Identify the most recent file (which is the first one in the list due to the order by date descending)
  44. set "most_recent_file="
  45. for /f "tokens=*" %%g in ('type "!temp_file!"') do (
  46.     if not defined most_recent_file set "most_recent_file=%%g"
  47. )
  48.  
  49. :: Check if the Dropbox directory exists and create if not
  50. if not exist "!DROPBOX_DIR!" mkdir "!DROPBOX_DIR!"
  51.  
  52. :: Copy the most recent file to the Dropbox directory
  53. if defined most_recent_file (
  54.     echo Copying the most recent file: !most_recent_file! to Dropbox...
  55.     copy "!BACKUP_DIR!\!most_recent_file!" "!DROPBOX_DIR!"
  56.     echo Most recent file copied successfully.
  57. ) else (
  58.     echo No files were found to copy.
  59. )
  60.  
  61. :: Clean up the temporary file
  62. del "!temp_file!"
  63.  
  64. endlocal
  65.  
Tags: minecraft
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement