finicu212

Untitled

Aug 11th, 2023
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. @echo off
  2.  
  3. REM Set the paths
  4. set SERVER_PATH=sv
  5. set GOOGLE_DRIVE_BACKUP_PATH=G:\My Drive\_AutoBackupMc
  6.  
  7. REM Create a timestamp for the backup
  8. for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set datetime=%%a
  9. set BACKUP_NAME=backup_%datetime:~0,8%_%datetime:~8,6%.zip
  10.  
  11. REM Zip the server directory
  12. powershell -command "Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('%SERVER_PATH%', '%GOOGLE_DRIVE_BACKUP_PATH%\%BACKUP_NAME%')"
  13.  
  14. REM Cleanup old backups
  15. powershell -command "& {
  16. $backupPath = 'G:\My Drive\_AutoBackupMc'
  17. $backups = Get-ChildItem $backupPath -Filter 'backup_*.zip' | Sort-Object LastAccessTime | Select-Object -First ($_.Count - 4)
  18. $backups | ForEach-Object { Remove-Item $_.FullName }
  19. }"
  20.  
  21. echo Backup completed!
  22.  
Advertisement
Add Comment
Please, Sign In to add comment