Windscythe Posted October 26, 2018 Posted October 26, 2018 Over the years I've hosted a few dedicated game server, and one of the main issues I've encountered is not having a proper backup solution. I'm trying to come up with a script that would run in the background with some specific parameters. My skill and knowledge of autoit is pretty basic, and most things that I've learned, I have gleaned from a lot of the helpful posts here. With that said, I haven't been able to patch together a script that will do what I'm trying to accomplish. Backup Script Requirements Performs backup of a single folder every x minutes (i.e Once every 20 minutes) Creates New Folder with Date and Time in the name Does not overwrite Backup Folders that have already been saved. Delete oldest folder beyond the x number (i.e 20th) backup If possible, use 7zip to zip the backup I'm not sure if I should try and just make a bat file to do what I'm trying to accomplish and then have it run once every 20 minutes, or if I it would be possible to have autoit handle all of it. Thank you for taking a look, and I appreciate any insight and help.
Windscythe Posted October 26, 2018 Author Posted October 26, 2018 This is the current PowerShell Script that I'm using. I did not write this. Credit: newbe5 and Lodur $timeofbackup = Get-Date -Format "yyyy-MM-dd-(HH-mm-ss)" $filenamepostfix = "ServerBackup" $backuplocation = "C:\SERVER\Backups" $backuplocationtemp = "C:\SERVER\Backups\Temp" $savefolder = "C:\SERVER\Saved" $maxbackupstokeep = 20 $usenewzipmethod = $true $filename = "$timeofbackup-$filenamepostfix.zip" Copy-Item "$savefolder" "$backuplocationtemp\Saved\" -Recurse if($usenewzipmethod -eq $true){ gci -Path "$backuplocationtemp" | Compress-Archive -DestinationPath "$backuplocation\$filename" } else { [Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal $includebasedir = $false [System.IO.Compression.ZipFile]::CreateFromDirectory("$backuplocationtemp","$backuplocation\$filename",$compressionLevel,$includebasedir) } Remove-Item "$backuplocationtemp\" -Recurse $tempcount = (Get-ChildItem "$backuplocation\*$filenamepostfix.zip" | measure).Count $difference = $tempcount-$maxbackupstokeep if($difference -gt 0) { Get-ChildItem "$backuplocation\*$filenamepostfix.zip" | Sort CreationTime | Select -First $difference | Remove-Item } Would it be possible to roll this into an AutoIt script, or to just make an AutoIt script that would execute this Once every 20 minutes?
careca Posted October 26, 2018 Posted October 26, 2018 (edited) If that can do what you require, yes, it's easy to make a loop with a timer and run that. Start by creating a loop and check the timer functions and examples in the help file. Edited October 26, 2018 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
Windscythe Posted October 27, 2018 Author Posted October 27, 2018 So basically what I'm currently struggling with is this. I have a powershell ps1 script: see above, I then created a batch file that runs the ps1 file. I am using AutoIT to execute the batch file that executes the ps1 file. I'm doing this so that I can have AutoIT execute the batch file every 20 minutes on a loop. The problem is that if I execute the batch file manually, everything works just fine. If I use AutoIT to execute the batch file, it starts the process, but gives an error after about 30 seconds and then shuts down. Here is the current AutoIT script that I'm using. If anyone can point out where I've messed up. while 1 If ProcessExists("Server.exe") then ShellExecute("C:\SERVER\Tools\RUNSERVERBACKUP.bat", "", "C:\SERVER\Tools") EndIf Sleep(1200000) WEnd
Windscythe Posted October 27, 2018 Author Posted October 27, 2018 I think I may have figured out the issue. Apparently running the AutoIT Script in x64 mode makes a difference. I'm still very open to input on my current script setup. It would be awesome of I could consolidate all of this down to just an AutoIT Script and not have to use the batch file and powershell. Thank you again.
FrancescoDiMuro Posted October 27, 2018 Posted October 27, 2018 @Windscythe Instead of using the Sleep command with that amount of seconds, you could run your script through Windows Task Scheduler every 20 minutes. Your script has to check if the main process ( your server ) is running, and if it is, then do whatever you want; else, it will exit immediately, without waiting 20 minutes to do the check again. You could use an .ini file in which you store all the information needed to manage your backups... I.e. the last backup, in date/time format, the files/folders to backup, the folder where you put your backup, and so on... To use 7-Zip to do your backups, you can use its command line parameters, even if there are a tons of UDFs to compress data. Start to take a look at Dir* functions, File* functions, _File* functions, Ini* functions and Process* functions. Cheers Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Earthshine Posted October 27, 2018 Posted October 27, 2018 You are overthinking it. I will share my backup function that allows you to copy whole dir or just the files you care about. It also date/time stames then and all are unique so nobody gets overwritten My resources are limited. You must ask the right questions
Earthshine Posted October 27, 2018 Posted October 27, 2018 (edited) Here. Try this take both files from second post the test.au3 is just to test the udf You can find log4a.au3 on this forum as well and is included in my post Edited October 27, 2018 by Earthshine My resources are limited. You must ask the right questions
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now