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